motion-support 0.0.3 → 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.
- data/lib/motion-support/array.rb +23 -0
- data/lib/motion-support/hash.rb +10 -0
- data/lib/motion-support/inflector.rb +156 -0
- data/lib/motion-support/nilclass.rb +5 -0
- data/lib/motion-support/{blank.rb → object.rb} +0 -7
- data/lib/motion-support/string.rb +59 -15
- data/lib/motion-support/version.rb +1 -1
- data/spec/motion-support/array_spec.rb +21 -0
- data/spec/motion-support/hash_spec.rb +25 -9
- data/spec/motion-support/inflector_spec.rb +65 -0
- data/spec/motion-support/nilclass_spec.rb +5 -0
- data/spec/motion-support/{blank_spec.rb → object_spec.rb} +6 -4
- data/spec/motion-support/string_spec.rb +113 -11
- metadata +16 -7
@@ -0,0 +1,23 @@
|
|
1
|
+
class Array
|
2
|
+
def empty?
|
3
|
+
self.length < 1
|
4
|
+
end
|
5
|
+
|
6
|
+
# If any item in the array has the key == `key` true, otherwise false.
|
7
|
+
# Of good use when writing specs.
|
8
|
+
def has_hash_key?(key)
|
9
|
+
self.each do |entity|
|
10
|
+
return true if entity.has_key? key
|
11
|
+
end
|
12
|
+
return false
|
13
|
+
end
|
14
|
+
|
15
|
+
# If any item in the array has the value == `key` true, otherwise false
|
16
|
+
# Of good use when writing specs.
|
17
|
+
def has_hash_value?(key)
|
18
|
+
self.each do |entity|
|
19
|
+
entity.each_pair{|hash_key, value| return true if value == key}
|
20
|
+
end
|
21
|
+
return false
|
22
|
+
end
|
23
|
+
end
|
data/lib/motion-support/hash.rb
CHANGED
@@ -18,4 +18,14 @@ class Hash
|
|
18
18
|
def symbolize_keys!
|
19
19
|
replace(symbolize_keys)
|
20
20
|
end
|
21
|
+
|
22
|
+
def empty?
|
23
|
+
self.length < 1
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns the contents of the hash, with the exception
|
27
|
+
# of the keys specified in the keys array.
|
28
|
+
def except(*keys)
|
29
|
+
self.dup.reject{|k, v| keys.include?(k)}
|
30
|
+
end
|
21
31
|
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# Inflector is a singleton class that helps
|
2
|
+
# singularize, pluralize and other-thing-ize
|
3
|
+
# words. It is very much based on the Rails
|
4
|
+
# ActiveSupport implementation or Inflector
|
5
|
+
class Inflector
|
6
|
+
def self.instance #nodoc
|
7
|
+
@__instance__ ||= new
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize #nodoc
|
11
|
+
reset
|
12
|
+
end
|
13
|
+
|
14
|
+
def reset
|
15
|
+
# Put singular-form to plural form transformations here
|
16
|
+
@plurals = [
|
17
|
+
[/^person$/, 'people'],
|
18
|
+
[/^man$/, 'men'],
|
19
|
+
[/^child$/, 'children'],
|
20
|
+
[/^sex$/, 'sexes'],
|
21
|
+
[/^move$/, 'moves'],
|
22
|
+
[/^cow$/, 'kine'],
|
23
|
+
[/^zombie$/, 'zombies'],
|
24
|
+
[/(quiz)$/i, '\1zes'],
|
25
|
+
[/^(oxen)$/i, '\1'],
|
26
|
+
[/^(ox)$/i, '\1en'],
|
27
|
+
[/^(m|l)ice$/i, '\1ice'],
|
28
|
+
[/^(m|l)ouse$/i, '\1ice'],
|
29
|
+
[/(matr|vert|ind)(?:ix|ex)$/i, '\1ices'],
|
30
|
+
[/(x|ch|ss|sh)$/i, '\1es'],
|
31
|
+
[/([^aeiouy]|qu)y$/i, '\1ies'],
|
32
|
+
[/(hive)$/i, '\1s'],
|
33
|
+
[/(?:([^f])fe|([lr])f)$/i, '\1\2ves'],
|
34
|
+
[/sis$/i, 'ses'],
|
35
|
+
[/([ti])a$/i, '\1a'],
|
36
|
+
[/([ti])um$/i, '\1a'],
|
37
|
+
[/(buffal|tomat)o$/i, '\1oes'],
|
38
|
+
[/(bu)s$/i, '\1ses'],
|
39
|
+
[/(alias|status)$/i, '\1es'],
|
40
|
+
[/(octop|vir)i$/i, '\1i'],
|
41
|
+
[/(octop|vir|alumn)us$/i, '\1i'],
|
42
|
+
[/^(ax|test)is$/i, '\1es'],
|
43
|
+
[/s$/i, 's'],
|
44
|
+
[/$/, 's']
|
45
|
+
]
|
46
|
+
|
47
|
+
# Put plural-form to singular form transformations here
|
48
|
+
@singulars = [
|
49
|
+
[/^people$/, 'person'],
|
50
|
+
[/^men$/, 'man'],
|
51
|
+
[/^children$/, 'child'],
|
52
|
+
[/^sexes$/, 'sex'],
|
53
|
+
[/^moves$/, 'move'],
|
54
|
+
[/^kine$/, 'cow'],
|
55
|
+
[/^zombies$/, 'zombie'],
|
56
|
+
[/(database)s$/i, '\1'],
|
57
|
+
[/(quiz)zes$/i, '\1'],
|
58
|
+
[/(matr)ices$/i, '\1ix'],
|
59
|
+
[/(vert|ind)ices$/i, '\1ex'],
|
60
|
+
[/^(ox)en/i, '\1'],
|
61
|
+
[/(alias|status)(es)?$/i, '\1'],
|
62
|
+
[/(octop|vir|alumn)(us|i)$/i, '\1us'],
|
63
|
+
[/^(a)x[ie]s$/i, '\1xis'],
|
64
|
+
[/(cris|test)(is|es)$/i, '\1is'],
|
65
|
+
[/(shoe)s$/i, '\1'],
|
66
|
+
[/(o)es$/i, '\1'],
|
67
|
+
[/(bus)(es)?$/i, '\1'],
|
68
|
+
[/^(m|l)ice$/i, '\1ouse'],
|
69
|
+
[/(x|ch|ss|sh)es$/i, '\1'],
|
70
|
+
[/(m)ovies$/i, '\1ovie'],
|
71
|
+
[/(s)eries$/i, '\1eries'],
|
72
|
+
[/([^aeiouy]|qu)ies$/i, '\1y'],
|
73
|
+
[/([lr])ves$/i, '\1f'],
|
74
|
+
[/(tive)s$/i, '\1'],
|
75
|
+
[/(hive)s$/i, '\1'],
|
76
|
+
[/([^f])ves$/i, '\1fe'],
|
77
|
+
[/(^analy)(sis|ses)$/i, '\1sis'],
|
78
|
+
[/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, '\1sis'],
|
79
|
+
[/([ti])a$/i, '\1um'],
|
80
|
+
[/(n)ews$/i, '\1ews'],
|
81
|
+
[/(ss)$/i, '\1'],
|
82
|
+
[/s$/i, '']
|
83
|
+
]
|
84
|
+
|
85
|
+
@irregulars = [
|
86
|
+
]
|
87
|
+
|
88
|
+
@uncountables = [
|
89
|
+
'equipment',
|
90
|
+
'information',
|
91
|
+
'rice',
|
92
|
+
'money',
|
93
|
+
'species',
|
94
|
+
'series',
|
95
|
+
'fish',
|
96
|
+
'sheep',
|
97
|
+
'jeans',
|
98
|
+
'police'
|
99
|
+
]
|
100
|
+
end
|
101
|
+
|
102
|
+
attr_reader :plurals, :singulars, :uncountables, :irregulars
|
103
|
+
|
104
|
+
def self.inflections
|
105
|
+
if block_given?
|
106
|
+
yield Inflector.instance
|
107
|
+
else
|
108
|
+
Inflector.instance
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def uncountable(word)
|
113
|
+
@uncountables << word
|
114
|
+
end
|
115
|
+
|
116
|
+
def singular(rule, replacement)
|
117
|
+
@singulars << [rule, replacement]
|
118
|
+
end
|
119
|
+
|
120
|
+
def plural(rule, replacement)
|
121
|
+
@plurals << [rule, replacement]
|
122
|
+
end
|
123
|
+
|
124
|
+
def irregular(rule, replacement)
|
125
|
+
@irregulars << [rule, replacement]
|
126
|
+
end
|
127
|
+
|
128
|
+
def uncountable?(word)
|
129
|
+
return word if @uncountables.include?(word.downcase)
|
130
|
+
false
|
131
|
+
end
|
132
|
+
|
133
|
+
def inflect(word, direction) #nodoc
|
134
|
+
return word if uncountable?(word)
|
135
|
+
|
136
|
+
subject = word.dup
|
137
|
+
|
138
|
+
@irregulars.each do |rule|
|
139
|
+
return subject if subject.gsub!(rule.first, rule.last)
|
140
|
+
end
|
141
|
+
|
142
|
+
sense_group = direction == :singularize ? @singulars : @plurals
|
143
|
+
sense_group.each do |rule|
|
144
|
+
return subject if subject.gsub!(rule.first, rule.last)
|
145
|
+
end
|
146
|
+
subject
|
147
|
+
end
|
148
|
+
|
149
|
+
def singularize(word)
|
150
|
+
inflect word, :singularize
|
151
|
+
end
|
152
|
+
|
153
|
+
def pluralize(word)
|
154
|
+
inflect word, :pluralize
|
155
|
+
end
|
156
|
+
end
|
@@ -1,27 +1,71 @@
|
|
1
1
|
class String
|
2
|
-
|
3
|
-
|
2
|
+
def humanize
|
3
|
+
self.gsub(/(_|-)+/, ' ').strip
|
4
|
+
end
|
5
|
+
|
6
|
+
def titleize
|
7
|
+
self.humanize.split(' ').map { |word| word.capitalize }.join(' ')
|
8
|
+
end
|
9
|
+
|
10
|
+
def dasherize
|
11
|
+
self.underscore.humanize.split(' ').join('-')
|
12
|
+
end
|
13
|
+
|
14
|
+
def empty?
|
15
|
+
self.length < 1
|
16
|
+
end
|
17
|
+
|
18
|
+
def blank?
|
19
|
+
self.strip.empty?
|
20
|
+
end
|
21
|
+
|
4
22
|
def pluralize
|
5
|
-
|
6
|
-
self
|
7
|
-
else
|
8
|
-
self + "s"
|
9
|
-
end
|
23
|
+
Inflector.inflections.pluralize self
|
10
24
|
end
|
11
25
|
|
12
|
-
# Returns a singularized version of the string, if it is not already pluralized. This implementation
|
13
|
-
# is rather naive, as it only removes a trailing 's' from the string, unless it does not end in 's'.
|
14
26
|
def singularize
|
15
|
-
|
16
|
-
|
27
|
+
Inflector.inflections.singularize self
|
28
|
+
end
|
29
|
+
|
30
|
+
def camelize(uppercase_first_letter = true)
|
31
|
+
string = self.dup
|
32
|
+
string.gsub!(/(?:_|-|(\/))([a-z\d]*)/i) do
|
33
|
+
new_word = $2.downcase
|
34
|
+
new_word[0] = new_word[0].upcase
|
35
|
+
new_word = "/#{new_word}" if $1 == '/'
|
36
|
+
new_word
|
37
|
+
end
|
38
|
+
if uppercase_first_letter && uppercase_first_letter != :lower
|
39
|
+
string[0] = string[0].upcase
|
17
40
|
else
|
18
|
-
|
41
|
+
string[0] = string[0].downcase
|
19
42
|
end
|
43
|
+
string.gsub!('/', '::')
|
44
|
+
string
|
20
45
|
end
|
21
|
-
|
22
|
-
|
23
|
-
|
46
|
+
|
47
|
+
def underscore
|
48
|
+
word = self.dup
|
49
|
+
word.gsub!(/::/, '/')
|
50
|
+
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
|
51
|
+
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
52
|
+
word.tr!("-", "_")
|
53
|
+
word.downcase!
|
54
|
+
word
|
55
|
+
end
|
56
|
+
|
57
|
+
# Make a string *named* like a class name. This means
|
58
|
+
# an under_scored string will become a CamelizedString, also it
|
59
|
+
# will be singularized, if it is plural.
|
24
60
|
def classify
|
25
61
|
singularize.camelize
|
26
62
|
end
|
63
|
+
|
64
|
+
# This method looks up a class name in the ObjectSpace's constants
|
65
|
+
# allowing you to do something like this:
|
66
|
+
#
|
67
|
+
# "under_scored".classify.contantize.new
|
68
|
+
def constantize
|
69
|
+
Object.const_get(self)
|
70
|
+
end
|
27
71
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
describe 'array' do
|
2
|
+
it 'determines when an array is empty' do
|
3
|
+
[1, 2, 3].should.not.be.empty
|
4
|
+
[].should.be.empty
|
5
|
+
end
|
6
|
+
|
7
|
+
it 'finds hash values' do
|
8
|
+
array_of_hashes = [
|
9
|
+
{
|
10
|
+
line1: 3,
|
11
|
+
line2: 5
|
12
|
+
},
|
13
|
+
{
|
14
|
+
line3: 7,
|
15
|
+
line4: 9
|
16
|
+
}
|
17
|
+
]
|
18
|
+
array_of_hashes.has_hash_value?(5).should.be.true
|
19
|
+
array_of_hashes.has_hash_value?(4).should.not.be.true
|
20
|
+
end
|
21
|
+
end
|
@@ -1,15 +1,31 @@
|
|
1
1
|
describe "hash" do
|
2
|
-
|
3
|
-
|
2
|
+
describe "symbolize_keys" do
|
3
|
+
it "should return copy with symbolized keys" do
|
4
|
+
{ 'foo' => 'bar', 'bla' => 'blub' }.symbolize_keys.should == { :foo => 'bar', :bla => 'blub' }
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should not modify keys that can not be symbolized" do
|
8
|
+
{ :foo => 'bar', 1 => 'blub' }.symbolize_keys.should == { :foo => 'bar', 1 => 'blub' }
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should symbolize keys in place" do
|
12
|
+
hash = { 'foo' => 'bar', 'bla' => 'blub' }
|
13
|
+
hash.symbolize_keys!
|
14
|
+
hash.should == { :foo => 'bar', :bla => 'blub' }
|
15
|
+
end
|
4
16
|
end
|
5
|
-
|
6
|
-
|
7
|
-
|
17
|
+
|
18
|
+
describe "empty?" do
|
19
|
+
it "reports an empty hash using empty?" do
|
20
|
+
{:key => 'value'}.empty?.should.not.be.true
|
21
|
+
{}.empty?.should.be.true
|
22
|
+
end
|
8
23
|
end
|
9
24
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
25
|
+
describe "except" do
|
26
|
+
it "creates sub-hashes using except" do
|
27
|
+
{:a => 'a', :b => 'b'}.except(:b)[:b].should.be.nil
|
28
|
+
{:a => 'a', :b => 'b'}.except(:b).length.should == 1
|
29
|
+
end
|
14
30
|
end
|
15
31
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
describe 'Extensions' do
|
2
|
+
describe 'Pluralization' do
|
3
|
+
it 'pluralizes a normal word: dog' do
|
4
|
+
Inflector.inflections.pluralize('dog').should == 'dogs'
|
5
|
+
end
|
6
|
+
|
7
|
+
it 'pluralizes words that end in "s": pass' do
|
8
|
+
Inflector.inflections.pluralize('pass').should == 'passes'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "pluralizes words that end in 'us'" do
|
12
|
+
Inflector.inflections.pluralize('alumnus').should == 'alumni'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "pluralizes words that end in 'ee'" do
|
16
|
+
Inflector.inflections.pluralize('attendee').should == 'attendees'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "pluralizes words that end in 'e'" do
|
20
|
+
Inflector.inflections.pluralize('article').should == 'articles'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'Singularization' do
|
25
|
+
it 'singularizes a normal word: "dogs"' do
|
26
|
+
Inflector.inflections.singularize('dogs').should == 'dog'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "singualarizes a word that ends in 's': passes" do
|
30
|
+
Inflector.inflections.singularize('passes').should == 'pass'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "singualarizes a word that ends in 'ee': assignees" do
|
34
|
+
Inflector.inflections.singularize('assignees').should == 'assignee'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "singualarizes words that end in 'us'" do
|
38
|
+
Inflector.inflections.singularize('alumni').should == 'alumnus'
|
39
|
+
end
|
40
|
+
|
41
|
+
it "singualarizes words that end in 'es'" do
|
42
|
+
Inflector.inflections.singularize('articles').should == 'article'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'Irregular Patterns' do
|
47
|
+
it "handles person to people singularizing" do
|
48
|
+
Inflector.inflections.singularize('people').should == 'person'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "handles person to people pluralizing" do
|
52
|
+
Inflector.inflections.pluralize('person').should == 'people'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'Adding Rules to Inflector' do
|
57
|
+
it 'accepts new rules' do
|
58
|
+
Inflector.inflections.irregular /^foot$/, 'feet'
|
59
|
+
Inflector.inflections.irregular /^feet$/, 'foot'
|
60
|
+
Inflector.inflections.pluralize('foot').should == 'feet'
|
61
|
+
Inflector.inflections.singularize('feet').should == 'foot'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -1,5 +1,5 @@
|
|
1
|
-
describe "
|
2
|
-
describe "
|
1
|
+
describe "Object" do
|
2
|
+
describe "blank?" do
|
3
3
|
it "should be blank when responds to empty and is empty" do
|
4
4
|
[].respond_to?(:empty?).should == true
|
5
5
|
[].blank?.should == true
|
@@ -9,7 +9,9 @@ describe "blank" do
|
|
9
9
|
"Teststring".respond_to?(:empty?).should == true
|
10
10
|
"Teststring".blank?.should == false
|
11
11
|
end
|
12
|
-
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "present?" do
|
13
15
|
it "should be present if not blank" do
|
14
16
|
"Hello".present?.should == true
|
15
17
|
end
|
@@ -19,7 +21,7 @@ describe "blank" do
|
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
|
-
describe "common objects" do
|
24
|
+
describe "common blank objects" do
|
23
25
|
it "should be blank for empty array" do
|
24
26
|
[].blank?.should == true
|
25
27
|
end
|
@@ -1,43 +1,145 @@
|
|
1
1
|
describe "string" do
|
2
|
+
describe "humanize" do
|
3
|
+
it "handles dashes in text" do
|
4
|
+
'text-with-dashes'.humanize.should == 'text with dashes'
|
5
|
+
end
|
6
|
+
|
7
|
+
it "doesn't add junk at end if trailing character is a dash" do
|
8
|
+
'text-with-trailing-dash-'.humanize.should == 'text with trailing dash'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "doesn't prepend junk if starting character is a dash" do
|
12
|
+
'-text-with-leading-dash'.humanize.should == 'text with leading dash'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "condenses multiple dashes to one space" do
|
16
|
+
'text--with-multiple--dashes'.humanize.should == 'text with multiple dashes'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "titleize" do
|
21
|
+
it "translates text to title case" do
|
22
|
+
'text-to-translate'.titleize.should == 'Text To Translate'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "dasherize" do
|
27
|
+
it 'handles strings with spaces' do
|
28
|
+
'a normal string'.dasherize.should == 'a-normal-string'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'handles CamelCase strings' do
|
32
|
+
'MyClass'.dasherize.should == 'my-class'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'handles snake_case strings' do
|
36
|
+
'my_class'.dasherize.should == 'my-class'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "empty?" do
|
41
|
+
it "an empty string is detected by empty?" do
|
42
|
+
''.empty?.should.be.true
|
43
|
+
end
|
44
|
+
|
45
|
+
it "a non-empty string is false according to empty?" do
|
46
|
+
'something'.empty?.should.not.be.true
|
47
|
+
end
|
48
|
+
|
49
|
+
it "a blank string is false according to empty?" do
|
50
|
+
' '.empty?.should.not.be.true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "blank?" do
|
55
|
+
it "an empty string should be blank" do
|
56
|
+
''.should.be.blank
|
57
|
+
end
|
58
|
+
|
59
|
+
it "a string containing only whitespace should be blank" do
|
60
|
+
' '.should.be.blank
|
61
|
+
end
|
62
|
+
|
63
|
+
it "a string with content is not blank" do
|
64
|
+
'abc'.should.not.be.blank
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "camelize" do
|
69
|
+
it 'a dashed string should convert to CamelCase' do
|
70
|
+
'my-class'.camelize.should == 'MyClass'
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'a snake_case string should convert to CamelCase' do
|
74
|
+
'my_class'.camelize.should == 'MyClass'
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'a conversion can be specified with lowercase first letter' do
|
78
|
+
'my_cocoa_var'.camelize(false).should == 'myCocoaVar'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "underscore" do
|
83
|
+
it 'a camel-cased string can be converted to snake-case' do
|
84
|
+
'MyClass'.underscore.should == 'my_class'
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'a module scoped class is properly underscored' do
|
88
|
+
'MyModule::MyClass'.underscore.should == 'my_module/my_class'
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'properly underscores lowercase initial letter' do
|
92
|
+
'aCocoaVariable'.underscore.should == 'a_cocoa_variable'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
2
96
|
describe "pluralize" do
|
3
97
|
it "should return self if string is already plural" do
|
4
98
|
"houses".pluralize.should == "houses"
|
5
99
|
"trains".pluralize.should == "trains"
|
6
100
|
end
|
7
|
-
|
101
|
+
|
8
102
|
it "should return plural version for singular string" do
|
9
103
|
"house".pluralize.should == "houses"
|
10
104
|
"train".pluralize.should == "trains"
|
11
105
|
end
|
12
106
|
end
|
13
|
-
|
107
|
+
|
14
108
|
describe "singularize" do
|
15
109
|
it "should return self if string is already singular" do
|
16
110
|
"house".singularize.should == "house"
|
17
111
|
"train".singularize.should == "train"
|
18
112
|
end
|
19
|
-
|
113
|
+
|
20
114
|
it "should return singular version for plural string" do
|
21
115
|
"houses".singularize.should == "house"
|
22
116
|
"trains".singularize.should == "train"
|
23
117
|
end
|
24
118
|
end
|
25
|
-
|
119
|
+
|
26
120
|
describe "classify" do
|
27
|
-
it "should return classified
|
121
|
+
it "should return classified version of underscored singular string" do
|
28
122
|
"search_controller".classify.should == "SearchController"
|
29
123
|
end
|
30
|
-
|
31
|
-
it "should return classified
|
124
|
+
|
125
|
+
it "should return classified version of underscored plural string" do
|
32
126
|
"search_controllers".classify.should == "SearchController"
|
33
127
|
end
|
34
|
-
|
35
|
-
it "should return classified
|
128
|
+
|
129
|
+
it "should return classified version of camelized singular string" do
|
36
130
|
"SearchController".classify.should == "SearchController"
|
37
131
|
end
|
38
|
-
|
39
|
-
it "should return classified
|
132
|
+
|
133
|
+
it "should return classified version of camelized plural string" do
|
40
134
|
"SearchControllers".classify.should == "SearchController"
|
41
135
|
end
|
42
136
|
end
|
137
|
+
|
138
|
+
describe "constantize" do
|
139
|
+
class SearchController; end
|
140
|
+
|
141
|
+
it "makes a constant class name from a suitable string" do
|
142
|
+
"SearchControllers".classify.constantize.should == SearchController
|
143
|
+
end
|
144
|
+
end
|
43
145
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: motion-support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0
|
5
|
+
version: 0.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Thomas Kadauke
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2013-03-14 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bubble-wrap
|
@@ -50,22 +50,28 @@ files:
|
|
50
50
|
- Rakefile
|
51
51
|
- app/app_delegate.rb
|
52
52
|
- lib/motion-support.rb
|
53
|
-
- lib/motion-support/
|
53
|
+
- lib/motion-support/array.rb
|
54
54
|
- lib/motion-support/cattr_accessor.rb
|
55
55
|
- lib/motion-support/class_inheritable_accessor.rb
|
56
56
|
- lib/motion-support/class_inheritable_array.rb
|
57
57
|
- lib/motion-support/hash.rb
|
58
|
+
- lib/motion-support/inflector.rb
|
58
59
|
- lib/motion-support/logger.rb
|
59
60
|
- lib/motion-support/metaclass.rb
|
61
|
+
- lib/motion-support/nilclass.rb
|
62
|
+
- lib/motion-support/object.rb
|
60
63
|
- lib/motion-support/string.rb
|
61
64
|
- lib/motion-support/version.rb
|
62
65
|
- motion-support.gemspec
|
63
|
-
- spec/motion-support/
|
66
|
+
- spec/motion-support/array_spec.rb
|
64
67
|
- spec/motion-support/cattr_accessor_spec.rb
|
65
68
|
- spec/motion-support/class_inheritable_accessor_spec.rb
|
66
69
|
- spec/motion-support/class_inheritable_array_spec.rb
|
67
70
|
- spec/motion-support/hash_spec.rb
|
71
|
+
- spec/motion-support/inflector_spec.rb
|
68
72
|
- spec/motion-support/metaclass_spec.rb
|
73
|
+
- spec/motion-support/nilclass_spec.rb
|
74
|
+
- spec/motion-support/object_spec.rb
|
69
75
|
- spec/motion-support/string_spec.rb
|
70
76
|
homepage: https://github.com/tkadauke/motion-support
|
71
77
|
licenses: []
|
@@ -80,7 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
86
|
requirements:
|
81
87
|
- - ">="
|
82
88
|
- !ruby/object:Gem::Version
|
83
|
-
hash: -
|
89
|
+
hash: -605165508006699025
|
84
90
|
segments:
|
85
91
|
- 0
|
86
92
|
version: "0"
|
@@ -89,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
95
|
requirements:
|
90
96
|
- - ">="
|
91
97
|
- !ruby/object:Gem::Version
|
92
|
-
hash: -
|
98
|
+
hash: -605165508006699025
|
93
99
|
segments:
|
94
100
|
- 0
|
95
101
|
version: "0"
|
@@ -101,10 +107,13 @@ signing_key:
|
|
101
107
|
specification_version: 3
|
102
108
|
summary: Commonly useful extensions to the standard library for RubyMotion
|
103
109
|
test_files:
|
104
|
-
- spec/motion-support/
|
110
|
+
- spec/motion-support/array_spec.rb
|
105
111
|
- spec/motion-support/cattr_accessor_spec.rb
|
106
112
|
- spec/motion-support/class_inheritable_accessor_spec.rb
|
107
113
|
- spec/motion-support/class_inheritable_array_spec.rb
|
108
114
|
- spec/motion-support/hash_spec.rb
|
115
|
+
- spec/motion-support/inflector_spec.rb
|
109
116
|
- spec/motion-support/metaclass_spec.rb
|
117
|
+
- spec/motion-support/nilclass_spec.rb
|
118
|
+
- spec/motion-support/object_spec.rb
|
110
119
|
- spec/motion-support/string_spec.rb
|