string_utilities 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/README.md +123 -0
- data/lib/string_utils/version.rb +5 -0
- data/lib/string_utils.rb +30 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/string_utils_spec.rb +26 -0
- data/string_utils.gemspec +39 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '0394cd0b502f01b3fa6495f496b78bf5c3c7570942ccb0508c52b930d1074d9b'
|
4
|
+
data.tar.gz: 6abd0b36373b743a1b8ec1a0bc25e9802d6ec8f84324a179d9a8450421e8d3e6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4b5e6e1fc511635b71b0483923b7e3ff814812ecb4c443420b5698c9b74528e133898a58e11c4cc1eebe414f4a30dc55f29753b2c76ff5cb48fccc93b1826fda
|
7
|
+
data.tar.gz: e847f87768d9f1a69b8ba94b67b549635015f149a604713b593b22b0aab39a8975c72a27a2e7f9701a3fe64dbbd7910feaa50946ad717631eab55ce4bd51f8ab
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/README.md
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
|
2
|
+
# StringUtils
|
3
|
+
|
4
|
+
**StringUtils** is a Ruby gem that provides additional string manipulation utilities to make working with strings easier and more convenient. It includes methods for converting strings between different cases, reversing words, and more.
|
5
|
+
|
6
|
+
Author
|
7
|
+
Developed by [Shobhit Jain](https://github.com/shalini0517).
|
8
|
+
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'string_utils'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
```bash
|
21
|
+
bundle install
|
22
|
+
```
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
```bash
|
27
|
+
gem install string_utils
|
28
|
+
```
|
29
|
+
|
30
|
+
---
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
Require the gem in your Ruby application:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
require 'string_utils'
|
38
|
+
```
|
39
|
+
|
40
|
+
### Available Methods
|
41
|
+
|
42
|
+
#### 1. `to_camel_case`
|
43
|
+
Converts a snake_case or kebab-case string into camelCase.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
StringUtils.to_camel_case("hello_world") # => "helloWorld"
|
47
|
+
```
|
48
|
+
|
49
|
+
#### 2. `to_kebab_case`
|
50
|
+
Converts a snake_case string into kebab-case.
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
StringUtils.to_kebab_case("hello_world") # => "hello-world"
|
54
|
+
```
|
55
|
+
|
56
|
+
#### 3. `to_snake_case`
|
57
|
+
Converts a string to snake_case, regardless of its original format.
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
StringUtils.to_snake_case("HelloWorld") # => "hello_world"
|
61
|
+
StringUtils.to_snake_case("hello-world") # => "hello_world"
|
62
|
+
```
|
63
|
+
|
64
|
+
#### 4. `title_case`
|
65
|
+
Capitalizes the first letter of each word while keeping certain words lowercase (like "and", "or", etc.).
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
StringUtils.title_case("the quick brown fox jumps over") # => "The Quick Brown Fox Jumps Over"
|
69
|
+
```
|
70
|
+
|
71
|
+
#### 5. `reverse_words`
|
72
|
+
Reverses the order of words in a sentence without reversing the characters in each word.
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
StringUtils.reverse_words("The quick brown fox") # => "fox brown quick The"
|
76
|
+
```
|
77
|
+
|
78
|
+
---
|
79
|
+
|
80
|
+
## Example Usage
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
require 'string_utils'
|
84
|
+
|
85
|
+
puts StringUtils.to_camel_case("my_example_string") # => "myExampleString"
|
86
|
+
puts StringUtils.to_kebab_case("my_example_string") # => "my-example-string"
|
87
|
+
puts StringUtils.to_snake_case("MyExampleString") # => "my_example_string"
|
88
|
+
puts StringUtils.title_case("a tale of two cities") # => "A Tale of Two Cities"
|
89
|
+
puts StringUtils.reverse_words("Hello World!") # => "World! Hello"
|
90
|
+
```
|
91
|
+
|
92
|
+
---
|
93
|
+
|
94
|
+
## Development
|
95
|
+
|
96
|
+
After checking out the repository, run `bin/setup` to install dependencies. Then, run the tests with:
|
97
|
+
|
98
|
+
```bash
|
99
|
+
bundle exec rspec
|
100
|
+
```
|
101
|
+
|
102
|
+
To install the gem locally:
|
103
|
+
|
104
|
+
```bash
|
105
|
+
gem build string_utils.gemspec
|
106
|
+
gem install ./string_utils-0.1.0.gem
|
107
|
+
```
|
108
|
+
|
109
|
+
---
|
110
|
+
|
111
|
+
## Contributing
|
112
|
+
|
113
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/shalini0517/string-utils](https://github.com/shalini0517/string-utils).
|
114
|
+
|
115
|
+
---
|
116
|
+
|
117
|
+
## License
|
118
|
+
|
119
|
+
This gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
120
|
+
|
121
|
+
## Code of Conduct
|
122
|
+
|
123
|
+
Everyone interacting in the CurrencyConverter project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/shalini0517/string-utils/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/string_utils.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "string_utils/version"
|
4
|
+
|
5
|
+
# string utils class
|
6
|
+
module StringUtils
|
7
|
+
def self.to_camel_case(str)
|
8
|
+
str.split("_").map.with_index { |word, i| i.zero? ? word : word.capitalize }.join
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.to_kebab_case(str)
|
12
|
+
str.gsub(/_/, "-").downcase
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.title_case(str)
|
16
|
+
little_words = %w[and or the a an in on at]
|
17
|
+
words = str.split(" ")
|
18
|
+
words.map.with_index do |word, index|
|
19
|
+
index.zero? || !little_words.include?(word.downcase) ? word.capitalize : word.downcase
|
20
|
+
end.join(" ")
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.reverse_words(str)
|
24
|
+
str.split(" ").reverse.join(" ")
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.to_snake_case(str)
|
28
|
+
str.gsub(/([A-Z])/, '_\1').gsub(/[-\s]/, "_").downcase.sub(/^_/, "")
|
29
|
+
end
|
30
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "string_utils"
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
# Enable flags like --only-failures and --next-failure
|
7
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
8
|
+
|
9
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
10
|
+
config.disable_monkey_patching!
|
11
|
+
|
12
|
+
config.expect_with :rspec do |c|
|
13
|
+
c.syntax = :expect
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require "string_utils"
|
5
|
+
|
6
|
+
RSpec.describe StringUtils do
|
7
|
+
it "converts snake_case to camelCase" do
|
8
|
+
expect(StringUtils.to_camel_case("hello_world")).to eq("helloWorld")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "converts string to kebab-case" do
|
12
|
+
expect(StringUtils.to_kebab_case("hello_world")).to eq("hello-world")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "capitalizes words correctly in title case" do
|
16
|
+
expect(StringUtils.title_case("the quick brown fox jumps over")).to eq("The Quick Brown Fox Jumps Over")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "reverses the words in a sentence" do
|
20
|
+
expect(StringUtils.reverse_words("The quick brown fox")).to eq("fox brown quick The")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "converts string to snake-case" do
|
24
|
+
expect(StringUtils.to_camel_case("hello_world")).to eq("helloWorld")
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/string_utils/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "string_utilities"
|
7
|
+
spec.version = StringUtils::VERSION
|
8
|
+
spec.authors = ["shalini0517"]
|
9
|
+
spec.email = ["shalinipatel1702@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "A Ruby gem for additional string manipulation utilities."
|
12
|
+
spec.description = "Provides methods like camelCase conversion,
|
13
|
+
kebab-case conversion, title casing, and reversing words."
|
14
|
+
spec.homepage = "https://github.com/shalini0517/string-utils"
|
15
|
+
spec.license = "MIT"
|
16
|
+
spec.required_ruby_version = ">= 3.0.0"
|
17
|
+
|
18
|
+
# Metadata links
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/shalini0517/string-utils"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/shalini0517/string-utils/blob/master/CHANGELOG.md"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released
|
24
|
+
# Exclude `.gem` and unnecessary files
|
25
|
+
spec.files = Dir.glob("{lib,spec}/**/*", base: __dir__) +
|
26
|
+
Dir.glob("*.{md,gemspec}", base: __dir__) -
|
27
|
+
Dir.glob("*.gem", base: __dir__)
|
28
|
+
|
29
|
+
# Specify the directory for executable files
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
# Add runtime dependencies here if needed
|
35
|
+
# Example: spec.add_dependency "example-gem", "~> 1.0"
|
36
|
+
|
37
|
+
# Add development dependencies here
|
38
|
+
spec.add_development_dependency "rspec", "~> 3.12"
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: string_utilities
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- shalini0517
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-12-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.12'
|
27
|
+
description: |-
|
28
|
+
Provides methods like camelCase conversion,
|
29
|
+
kebab-case conversion, title casing, and reversing words.
|
30
|
+
email:
|
31
|
+
- shalinipatel1702@gmail.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- CHANGELOG.md
|
37
|
+
- CODE_OF_CONDUCT.md
|
38
|
+
- README.md
|
39
|
+
- lib/string_utils.rb
|
40
|
+
- lib/string_utils/version.rb
|
41
|
+
- spec/spec_helper.rb
|
42
|
+
- spec/string_utils_spec.rb
|
43
|
+
- string_utils.gemspec
|
44
|
+
homepage: https://github.com/shalini0517/string-utils
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata:
|
48
|
+
homepage_uri: https://github.com/shalini0517/string-utils
|
49
|
+
source_code_uri: https://github.com/shalini0517/string-utils
|
50
|
+
changelog_uri: https://github.com/shalini0517/string-utils/blob/master/CHANGELOG.md
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 3.0.0
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubygems_version: 3.5.23
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: A Ruby gem for additional string manipulation utilities.
|
70
|
+
test_files: []
|