string_plus 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/string_plus.rb +8 -8
- data/lib/string_plus/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33d40d790b1ff9aea27718c7fdc4cb3c0fa7a71a
|
4
|
+
data.tar.gz: 3e0959e1393dd73ccdeae353acc6ed3f359fb4bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01afba878f61b8d169e6ead7c644a40b8301ca9c50287156d7ab0d1a1b71116c773bbb29cb71ca1307ad71a980f3cf13ecc550b5f5d8841a404f64341f40a82d
|
7
|
+
data.tar.gz: c781f36c8c5b6509ddb54202beb9a0eb6e8ad83e48335b444c6f1bfa74993b02a9681665f1dc984f72f5875b575675c27413a1ed295b39d976bc8c9092779fae
|
data/lib/string_plus.rb
CHANGED
@@ -2,10 +2,10 @@ require "string_plus/version"
|
|
2
2
|
|
3
3
|
module StringPlus
|
4
4
|
module_function
|
5
|
-
def camelcase(capitalize_first_char=true)
|
5
|
+
def camelcase(str=self, capitalize_first_char=true)
|
6
6
|
res = ""
|
7
7
|
flag = capitalize_first_char
|
8
|
-
|
8
|
+
str.each_char {|w|
|
9
9
|
(flag = true ; next) if w == "_" || w == " "
|
10
10
|
res << if flag
|
11
11
|
flag = false
|
@@ -17,14 +17,14 @@ module StringPlus
|
|
17
17
|
res
|
18
18
|
end
|
19
19
|
|
20
|
-
def lcamelcase
|
20
|
+
def lcamelcase(str=self)
|
21
21
|
camelcase(false)
|
22
22
|
end
|
23
23
|
|
24
|
-
def underscore
|
25
|
-
return
|
24
|
+
def underscore(str=self)
|
25
|
+
return str.downcase if str.each_char.all? { |c| c == c.upcase && c =~ /[a-zA-Z0-9]/}
|
26
26
|
res = ""
|
27
|
-
[nil, *
|
27
|
+
[nil, *str.each_char].each_cons(2) do |last, current|
|
28
28
|
res << "_" if last !=nil && current == current.upcase && !("0".."9").include?(current)
|
29
29
|
res << current.downcase unless current == " "
|
30
30
|
end
|
@@ -32,8 +32,8 @@ module StringPlus
|
|
32
32
|
end
|
33
33
|
alias :snakecase :underscore
|
34
34
|
|
35
|
-
def constantize
|
36
|
-
c =
|
35
|
+
def constantize(str=self)
|
36
|
+
c = str.split("-").map(&:camelcase).join("::")
|
37
37
|
Object.send(:const_get, c)
|
38
38
|
end
|
39
39
|
end
|
data/lib/string_plus/version.rb
CHANGED