change_case 0.1.0 → 0.2.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 +4 -4
- data/lib/change_case/version.rb +1 -1
- data/lib/change_case.rb +47 -13
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7817cff406767caf9479dd80308f1550788f2abea2172791268278ddb54c418
|
4
|
+
data.tar.gz: 8e75f7d079a02c7b35ff91dcbfa59cc6735271e20279dd5e4035ed25786283a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8a15b3fba0b0aaa52ffcfaf3e5096c3dcfd8b3ec70b09a9b5e6b1665ee6aafd524896ee7ab22220127211dcf44de97e55b2e22b9bc127c2551c200b61407bec
|
7
|
+
data.tar.gz: 947b624ad58fed2de66f16ee3d387f529e9eb8f8a4d8e1a34f1c160446360a47ed187a561d73427ff3b056e6b77c36469e1ecd3ea2795d9caa44f2bae46fc86f
|
data/lib/change_case/version.rb
CHANGED
data/lib/change_case.rb
CHANGED
@@ -4,50 +4,84 @@ require_relative "change_case/version"
|
|
4
4
|
|
5
5
|
module ChangeCase
|
6
6
|
def self.camel(input)
|
7
|
-
|
7
|
+
split_string(input).map.with_index { |word, i| i.zero? ? word : word.capitalize }.join
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.capital(input)
|
11
|
-
|
11
|
+
split_string(input).map(&:capitalize).join(" ")
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.constant(input)
|
15
|
-
|
15
|
+
split_string(input).join("_").upcase
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.dot(input)
|
19
|
-
|
19
|
+
split_string(input).join(".")
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.kebab(input)
|
23
|
-
|
23
|
+
split_string(input).join("-")
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.no(input)
|
27
|
-
|
27
|
+
split_string(input).join(" ")
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.pascal(input)
|
31
|
-
|
31
|
+
split_string(input).map(&:capitalize).join
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.pascal_snake(input)
|
35
|
+
split_string(input).map(&:capitalize).join("_")
|
32
36
|
end
|
33
37
|
|
34
38
|
def self.path(input)
|
35
|
-
|
39
|
+
split_string(input).join("/")
|
36
40
|
end
|
37
41
|
|
38
42
|
def self.sentence(input)
|
39
|
-
|
43
|
+
split_string(input).join(" ").capitalize
|
40
44
|
end
|
41
45
|
|
42
46
|
def self.snake(input)
|
43
|
-
|
47
|
+
split_string(input).join("_")
|
44
48
|
end
|
45
49
|
|
46
50
|
def self.train(input)
|
47
|
-
|
51
|
+
split_string(input).map(&:capitalize).join("-")
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.title(input)
|
55
|
+
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
|
+
split_string(input).map.with_index { |word, i| small_words.include?(word) && i.positive? ? word : word.capitalize }.join(" ")
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.swap(input)
|
60
|
+
input.swapcase
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.sponge(input)
|
64
|
+
input.chars.map { |char| rand(2).zero? ? char.downcase : char.upcase }.join
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.upper_first(input)
|
68
|
+
input.empty? ? "" : input[0].upcase.concat(input[1..])
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.lower_first(input)
|
72
|
+
input.empty? ? "" : input[0].downcase.concat(input[1..])
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.upper?(input)
|
76
|
+
input == input.upcase
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.lower?(input)
|
80
|
+
input == input.downcase
|
48
81
|
end
|
49
82
|
|
50
|
-
private_class_method def self.
|
51
|
-
input.to_s.strip.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z0-9])([A-Z])/, '\1_\2')
|
83
|
+
private_class_method def self.split_string(input)
|
84
|
+
input.to_s.strip.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z0-9])([A-Z])/, '\1_\2')
|
85
|
+
.downcase.split(/[^a-z0-9']+/).reject(&:empty?)
|
52
86
|
end
|
53
87
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Javier Rosales
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-01-
|
10
|
+
date: 2025-01-12 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
email:
|
13
13
|
- javier.rb_96@hotmail.com
|
@@ -20,7 +20,8 @@ files:
|
|
20
20
|
homepage: https://github.com/javoeria/change_case
|
21
21
|
licenses:
|
22
22
|
- MIT
|
23
|
-
metadata:
|
23
|
+
metadata:
|
24
|
+
homepage_uri: https://github.com/javoeria/change_case
|
24
25
|
rdoc_options: []
|
25
26
|
require_paths:
|
26
27
|
- lib
|