change_case 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7817cff406767caf9479dd80308f1550788f2abea2172791268278ddb54c418
4
- data.tar.gz: 8e75f7d079a02c7b35ff91dcbfa59cc6735271e20279dd5e4035ed25786283a4
3
+ metadata.gz: 3cc32b4cba960d81ff1c275a32d3184fa6bba468fa38dc020eebb86d95ced60d
4
+ data.tar.gz: a98036290d52e34276bbbc74f64326fff3056e65135311130c27d58a1e88ae56
5
5
  SHA512:
6
- metadata.gz: d8a15b3fba0b0aaa52ffcfaf3e5096c3dcfd8b3ec70b09a9b5e6b1665ee6aafd524896ee7ab22220127211dcf44de97e55b2e22b9bc127c2551c200b61407bec
7
- data.tar.gz: 947b624ad58fed2de66f16ee3d387f529e9eb8f8a4d8e1a34f1c160446360a47ed187a561d73427ff3b056e6b77c36469e1ecd3ea2795d9caa44f2bae46fc86f
6
+ metadata.gz: de7d6787223100cd5d4efe747b72e100258c551e828e0bdb9896608a4c4774bc39324ae82349eeb3caf899e1bb51ff1604ed871a0b3d82383e91705934b730fb
7
+ data.tar.gz: fe3cbe4baab5e60ddbfdb82ac927d1d08dfd42be08d7ea8173f929e2f03a5d5a3fed3b26f83121fabcd0ec35ca30981ca3455cab42f83949c5a157f466e38d55
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ ## [0.3.0] - 2025-01-16
2
+
3
+ - Include case methods to String class
4
+
5
+ ## [0.2.0] - 2025-01-12
6
+
7
+ - All case methods and refactor code
8
+
9
+ ## [0.1.0] - 2025-01-10
10
+
11
+ - Initial release
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # ChangeCase
2
+
3
+ Transform a string between `camelCase`, `PascalCase`, `Capital Case`, `snake_case`, `kebab-case`, `CONSTANT_CASE` and others.
4
+
5
+ [![Build Status](https://github.com/javoeria/change_case/actions/workflows/main.yml/badge.svg)](https://github.com/javoeria/change_case/actions/workflows/main.yml)
6
+ [![Gem Version](https://badge.fury.io/rb/change_case.svg)](https://rubygems.org/gems/change_case)
7
+
8
+ ## Installation
9
+
10
+ Install the gem and add to the application's Gemfile by executing:
11
+
12
+ ```bash
13
+ bundle add change_case
14
+ ```
15
+
16
+ If bundler is not being used to manage dependencies, install the gem by executing:
17
+
18
+ ```bash
19
+ gem install change_case
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ require "change_case"
26
+
27
+ ChangeCase.camel("TEST_VALUE") #=> "testValue"
28
+ # OR
29
+ "TEST_VALUE".camelcase #=> "testValue"
30
+ ```
31
+
32
+ Included case methods:
33
+
34
+ | ChangeCase | String | Result |
35
+ | -------------- | -------------- | ----------- |
36
+ | `camel` | `camelcase` | `twoWords` |
37
+ | `capital` | `capitalcase` | `Two Words` |
38
+ | `constant` | `constantcase` | `TWO_WORDS` |
39
+ | `dot` | `dotcase` | `two.words` |
40
+ | `kebab` | `kebabcae` | `two-words` |
41
+ | `no` | `nocase` | `two words` |
42
+ | `pascal` | `pascalcase` | `TwoWords` |
43
+ | `pascal_snake` | `pascalcase` | `Two_Words` |
44
+ | `path` | `pathcase` | `two/words` |
45
+ | `sentence` | `sentencecase` | `Two words` |
46
+ | `snake` | `snakecase` | `two_words` |
47
+ | `train` | `traincase` | `Two-Words` |
48
+ | `title` | `titlecase` | `Two Words` |
49
+ | `swap` | `swapcase` | `tWO wORDS` |
50
+ | `sponge` | `spongecase` | `TwO wORdS` |
51
+
52
+ ## Development
53
+
54
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
55
+
56
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
57
+
58
+ ## Contributing
59
+
60
+ Bug reports and pull requests are welcome on GitHub at https://github.com/javoeria/change_case.
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Add ChangeCase methods on the String class by monkey patching.
4
+ class String
5
+ # Converts the string to camel case.
6
+ def camelcase
7
+ ChangeCase.camel(self)
8
+ end
9
+
10
+ # Converts the string to capital case.
11
+ def capitalcase
12
+ ChangeCase.capital(self)
13
+ end
14
+
15
+ # Converts the string to constant case.
16
+ def constantcase
17
+ ChangeCase.constant(self)
18
+ end
19
+
20
+ # Converts the string to dot case.
21
+ def dotcase
22
+ ChangeCase.dot(self)
23
+ end
24
+
25
+ # Converts the string to kebab/param case.
26
+ def kebabcase
27
+ ChangeCase.kebab(self)
28
+ end
29
+
30
+ # Converts the string to space separated lowercase.
31
+ def nocase
32
+ ChangeCase.no(self)
33
+ end
34
+
35
+ # Converts the string to pascal case.
36
+ def pascalcase(snake: false)
37
+ snake ? ChangeCase.pascal_snake(self) : ChangeCase.pascal(self)
38
+ end
39
+
40
+ # Converts the string to path case.
41
+ def pathcase
42
+ ChangeCase.path(self)
43
+ end
44
+
45
+ # Converts the string to sentence case.
46
+ def sentencecase
47
+ ChangeCase.sentence(self)
48
+ end
49
+
50
+ # Converts the string to snake case.
51
+ def snakecase
52
+ ChangeCase.snake(self)
53
+ end
54
+
55
+ # Converts the string to train/header case.
56
+ def traincase
57
+ ChangeCase.train(self)
58
+ end
59
+
60
+ # Converts the string to title case.
61
+ def titlecase
62
+ ChangeCase.title(self)
63
+ end
64
+
65
+ # Converts the string with random capitalization applied.
66
+ def spongecase
67
+ ChangeCase.sponge(self)
68
+ end
69
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ChangeCase
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/change_case.rb CHANGED
@@ -1,81 +1,102 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "change_case/version"
4
+ require_relative "change_case/string"
4
5
 
6
+ # Module used for converting strings to any case.
5
7
  module ChangeCase
8
+ # Converts the string to camel case.
6
9
  def self.camel(input)
7
10
  split_string(input).map.with_index { |word, i| i.zero? ? word : word.capitalize }.join
8
11
  end
9
12
 
13
+ # Converts the string to capital case.
10
14
  def self.capital(input)
11
15
  split_string(input).map(&:capitalize).join(" ")
12
16
  end
13
17
 
18
+ # Converts the string to constant case.
14
19
  def self.constant(input)
15
20
  split_string(input).join("_").upcase
16
21
  end
17
22
 
23
+ # Converts the string to dot case.
18
24
  def self.dot(input)
19
25
  split_string(input).join(".")
20
26
  end
21
27
 
28
+ # Converts the string to kebab/param case.
22
29
  def self.kebab(input)
23
30
  split_string(input).join("-")
24
31
  end
25
32
 
33
+ # Converts the string to space separated lowercase.
26
34
  def self.no(input)
27
35
  split_string(input).join(" ")
28
36
  end
29
37
 
38
+ # Converts the string to pascal case.
30
39
  def self.pascal(input)
31
40
  split_string(input).map(&:capitalize).join
32
41
  end
33
42
 
43
+ # Converts the string to pascal snake case.
34
44
  def self.pascal_snake(input)
35
45
  split_string(input).map(&:capitalize).join("_")
36
46
  end
37
47
 
48
+ # Converts the string to path case.
38
49
  def self.path(input)
39
50
  split_string(input).join("/")
40
51
  end
41
52
 
53
+ # Converts the string to sentence case.
42
54
  def self.sentence(input)
43
55
  split_string(input).join(" ").capitalize
44
56
  end
45
57
 
58
+ # Converts the string to snake case.
46
59
  def self.snake(input)
47
60
  split_string(input).join("_")
48
61
  end
49
62
 
63
+ # Converts the string to train/header case.
50
64
  def self.train(input)
51
65
  split_string(input).map(&:capitalize).join("-")
52
66
  end
53
67
 
68
+ # Converts the string to title case.
54
69
  def self.title(input)
55
70
  small_words = %w[a an and as at because but by en for if in neither nor of on or only over per so some that than the to up upon vs versus via when with without yet]
56
71
  split_string(input).map.with_index { |word, i| small_words.include?(word) && i.positive? ? word : word.capitalize }.join(" ")
57
72
  end
58
73
 
74
+ # Converts the string with uppercase characters to lowercase and vice versa.
59
75
  def self.swap(input)
60
76
  input.swapcase
61
77
  end
62
78
 
79
+ # Converts the string with random capitalization applied.
63
80
  def self.sponge(input)
64
81
  input.chars.map { |char| rand(2).zero? ? char.downcase : char.upcase }.join
65
82
  end
66
83
 
84
+ # Converts the first character in the string to uppercase.
67
85
  def self.upper_first(input)
68
86
  input.empty? ? "" : input[0].upcase.concat(input[1..])
69
87
  end
70
88
 
89
+ # Converts the first character in the string to lowercase.
71
90
  def self.lower_first(input)
72
91
  input.empty? ? "" : input[0].downcase.concat(input[1..])
73
92
  end
74
93
 
94
+ # Returns +true+ if the string is uppercase only.
75
95
  def self.upper?(input)
76
96
  input == input.upcase
77
97
  end
78
98
 
99
+ # Returns +true+ if the string is lowercase only.
79
100
  def self.lower?(input)
80
101
  input == input.downcase
81
102
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: change_case
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Rosales
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-12 00:00:00.000000000 Z
10
+ date: 2025-01-16 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  email:
13
13
  - javier.rb_96@hotmail.com
@@ -15,7 +15,10 @@ executables: []
15
15
  extensions: []
16
16
  extra_rdoc_files: []
17
17
  files:
18
+ - CHANGELOG.md
19
+ - README.md
18
20
  - lib/change_case.rb
21
+ - lib/change_case/string.rb
19
22
  - lib/change_case/version.rb
20
23
  homepage: https://github.com/javoeria/change_case
21
24
  licenses: