reality-naming 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reality/naming.rb +4 -3
- data/reality-naming.gemspec +1 -1
- data/test/test_naming.rb +4 -3
- 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: 98022429208fe3e56df3aa63e04d05bc9d0404de
|
4
|
+
data.tar.gz: 30739b8f989d62c9cd7c41e12033233d3d4c349c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc453495f12e4286e2c401c1726b9cceecd88d0a0f0b761d3ac831d50e40cf26e28cda001271b6db764c10e950dc184f99cc9734a160e51f890a28b69cc728a8
|
7
|
+
data.tar.gz: 4f8b8af968cfaabb11aba3eafdbcc034c0e9748a84732306f10d18b76ea13f27bd310621d12cc9c68aa703adb32a8d58fa55eb46a8ba7a32dd01298f10abfc6c
|
data/lib/reality/naming.rb
CHANGED
@@ -21,7 +21,7 @@ module Reality
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def camelize(input_word)
|
24
|
-
word_parts = split_into_words(input_word).collect { |part| part[0...1].upcase + part[1..-1] }
|
24
|
+
word_parts = split_into_words(input_word, true).collect { |part| part[0...1].upcase + part[1..-1] }
|
25
25
|
return word_parts[0].downcase if (word_parts.size == 1 && word_parts[0] == word_parts[0].upcase)
|
26
26
|
word = word_parts.join('')
|
27
27
|
word[0...1].downcase + word[1..-1]
|
@@ -104,12 +104,13 @@ module Reality
|
|
104
104
|
pluralization_rules.clear
|
105
105
|
end
|
106
106
|
|
107
|
-
def split_into_words(word)
|
107
|
+
def split_into_words(word, downcase_all_upcased_words = false)
|
108
108
|
word = word.to_s.dup
|
109
109
|
word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
110
110
|
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
111
111
|
word.tr!('-', '_')
|
112
|
-
word.split('_')
|
112
|
+
result = word.split('_')
|
113
|
+
downcase_all_upcased_words ? result.collect{|w| w.upcase == w ? w.downcase : w } : result
|
113
114
|
end
|
114
115
|
|
115
116
|
private
|
data/reality-naming.gemspec
CHANGED
data/test/test_naming.rb
CHANGED
@@ -39,8 +39,8 @@ class TestNaming < Reality::Naming::TestCase
|
|
39
39
|
assert_equal Reality::Naming.pascal_case('ThisIsCamelCased'), 'ThisIsCamelCased'
|
40
40
|
assert_equal Reality::Naming.pascal_case('this_Is_Camel_Cased'), 'ThisIsCamelCased'
|
41
41
|
assert_equal Reality::Naming.pascal_case('this_Is_camel_cased'), 'ThisIsCamelCased'
|
42
|
-
assert_equal Reality::Naming.pascal_case('EJB'), '
|
43
|
-
assert_equal Reality::Naming.pascal_case('EJBContainer'), '
|
42
|
+
assert_equal Reality::Naming.pascal_case('EJB'), 'EJB'
|
43
|
+
assert_equal Reality::Naming.pascal_case('EJBContainer'), 'EJBContainer'
|
44
44
|
|
45
45
|
assert_equal Reality::Naming.pascal_case?('FindByID'), true
|
46
46
|
|
@@ -78,7 +78,8 @@ class TestNaming < Reality::Naming::TestCase
|
|
78
78
|
assert_equal %w(My Support Library), Reality::Naming.split_into_words('MySupportLibrary')
|
79
79
|
assert_equal %w(my support library), Reality::Naming.split_into_words('my-support-library')
|
80
80
|
assert_equal %w(my support library), Reality::Naming.split_into_words('my_support_library')
|
81
|
-
assert_equal %w(
|
81
|
+
assert_equal %w(MY SUPPORT LIBRARY), Reality::Naming.split_into_words('MY_SUPPORT_LIBRARY')
|
82
|
+
assert_equal %w(my support library), Reality::Naming.split_into_words('MY_SUPPORT_LIBRARY', true)
|
82
83
|
|
83
84
|
# ID is specially handled
|
84
85
|
assert_equal %w(Find By ID), Reality::Naming.split_into_words('FindByID')
|