sugarcube 1.4.3 → 1.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/sugarcube/version.rb +1 -1
- data/lib/sugarcube-anonymous/anonymous.rb +17 -1
- data/lib/sugarcube-files/nsstring.rb +2 -2
- data/spec/anonymous_spec.rb +60 -40
- data/spec/date_parser_spec.rb +6 -1
- data/spec/image_scale_spec.rb +18 -18
- data/spec/nsstring_files_spec.rb +3 -3
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/lib/sugarcube/version.rb
CHANGED
@@ -11,22 +11,38 @@ module SugarCube
|
|
11
11
|
# obj = {
|
12
12
|
# 'first_name': 'Katsuyoshi', # strings
|
13
13
|
# company: 'Ito Soft Design', # and symbols are supported
|
14
|
+
# great: true,
|
14
15
|
# }.to_object
|
15
16
|
#
|
16
17
|
# obj.first_name
|
17
18
|
# # => 'Katsuyoshi'
|
18
19
|
# obj.company
|
19
20
|
# # => 'Ito Soft Design'
|
21
|
+
# # adding a '?' will return true/false
|
22
|
+
# obj.great?
|
23
|
+
# # => true
|
24
|
+
# obj.great
|
25
|
+
# # => true
|
26
|
+
#
|
20
27
|
# obj.bla # => raises NoMethodError
|
21
28
|
# obj.bla = 'bla' # => raises NoMethodError
|
22
29
|
class Anonymous < Hash
|
23
30
|
|
24
31
|
def method_missing(symbol, *args)
|
25
32
|
if args.size == 0
|
33
|
+
if symbol.to_s[-1] == '?'
|
34
|
+
symbol = symbol.to_s[0...-1].to_sym
|
35
|
+
return_bool = true
|
36
|
+
else
|
37
|
+
return_bool = false
|
38
|
+
end
|
26
39
|
key = symbol
|
27
40
|
key = symbol.to_s unless self.include? key
|
28
41
|
if self.include?(key)
|
29
42
|
self[key] = self[key].to_object
|
43
|
+
if return_bool
|
44
|
+
return !! self[key]
|
45
|
+
end
|
30
46
|
return self[key]
|
31
47
|
end
|
32
48
|
elsif args.size == 1 && /(.*)=$/ =~ symbol.to_s
|
@@ -45,7 +61,7 @@ module SugarCube
|
|
45
61
|
|
46
62
|
# replace enumerable methods
|
47
63
|
alias :anonymous_each :each
|
48
|
-
|
64
|
+
|
49
65
|
def each
|
50
66
|
anonymous_each {|k,v| yield k, v.to_object}
|
51
67
|
end
|
@@ -29,13 +29,13 @@ class NSString
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def file_exists?
|
32
|
-
path = self.hasPrefix('/') ? self : self.
|
32
|
+
path = self.hasPrefix('/') ? self : self.document_path
|
33
33
|
NSFileManager.defaultManager.fileExistsAtPath(path)
|
34
34
|
end
|
35
35
|
|
36
36
|
def remove_file!
|
37
37
|
ptr = Pointer.new(:id)
|
38
|
-
path = self.hasPrefix('/') ? self : self.
|
38
|
+
path = self.hasPrefix('/') ? self : self.document_path
|
39
39
|
NSFileManager.defaultManager.removeItemAtPath(path, error:ptr)
|
40
40
|
ptr[0]
|
41
41
|
end
|
data/spec/anonymous_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
describe "SugarCube::Anonymous" do
|
2
2
|
|
3
3
|
before do
|
4
|
-
@h = SugarCube::Anonymous[{ foo: 'FOO', "bar" => 'BAR' }]
|
4
|
+
@h = SugarCube::Anonymous[{ foo: 'FOO', "bar" => 'BAR', falsey: nil, 'truthy' => 'yes!' }]
|
5
5
|
end
|
6
6
|
|
7
7
|
describe "NSDictionary#to_object" do
|
@@ -30,6 +30,14 @@ describe "SugarCube::Anonymous" do
|
|
30
30
|
@h.bar.should == 'BAR'
|
31
31
|
end
|
32
32
|
|
33
|
+
it 'should have an #truthy? method, and return true' do
|
34
|
+
@h.truthy?.should == true
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should have an #falsey? method, and return false' do
|
38
|
+
@h.falsey?.should == false
|
39
|
+
end
|
40
|
+
|
33
41
|
it 'should raise NoMethodError on non-existing keys' do
|
34
42
|
should.raise(NoMethodError) {
|
35
43
|
@h.hoge
|
@@ -50,6 +58,18 @@ describe "SugarCube::Anonymous" do
|
|
50
58
|
@h.bar.should == 'Bar'
|
51
59
|
end
|
52
60
|
|
61
|
+
it 'should have a #truthy= method, and return "True" and true' do
|
62
|
+
@h.truthy = 'True'
|
63
|
+
@h.truthy.should == 'True'
|
64
|
+
@h.truthy?.should == true
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should have a #falsey= method, and return nil and false' do
|
68
|
+
@h.falsey = nil
|
69
|
+
@h.falsey.should == nil
|
70
|
+
@h.falsey?.should == false
|
71
|
+
end
|
72
|
+
|
53
73
|
it 'should raise NoMethodError on non-existing keys' do
|
54
74
|
should.raise(NoMethodError) {
|
55
75
|
@h.hoge.should == 'Hoge'
|
@@ -71,50 +91,50 @@ describe "SugarCube::Anonymous nested case" do
|
|
71
91
|
}
|
72
92
|
]
|
73
93
|
end
|
74
|
-
|
94
|
+
|
75
95
|
describe "dictionary" do
|
76
|
-
|
96
|
+
|
77
97
|
it 'should return an instance of SugarCube::Anonymous' do
|
78
98
|
@h.dictionary.class.should == SugarCube::Anonymous
|
79
99
|
end
|
80
|
-
|
100
|
+
|
81
101
|
it 'should return a hash which contains a string and an array' do
|
82
102
|
@h.dictionary.should == { foo: 'FOO', array: [ { is_fine: 'is_fine' } ] }
|
83
103
|
end
|
84
|
-
|
104
|
+
|
85
105
|
it 'should not copy again' do
|
86
106
|
@h.dictionary.object_id.should == @h.dictionary.object_id
|
87
107
|
end
|
88
|
-
|
108
|
+
|
89
109
|
it 'should return is_fine' do
|
90
110
|
@h.dictionary.array[0].is_fine.should == 'is_fine'
|
91
111
|
end
|
92
|
-
|
112
|
+
|
93
113
|
describe "Enumerable" do
|
94
114
|
|
95
115
|
describe "each" do
|
96
|
-
|
116
|
+
|
97
117
|
it 'should return an instance of [SugarCube::Anonymous, SugarCube::AnonymousArray]' do
|
98
118
|
a = []
|
99
119
|
@h.each{|k,v| a << v.class}
|
100
120
|
a[0].should == SugarCube::Anonymous
|
101
121
|
a[1].should == SugarCube::AnonymousArray
|
102
122
|
end
|
103
|
-
|
123
|
+
|
104
124
|
end
|
105
125
|
|
106
126
|
describe "map" do
|
107
|
-
|
127
|
+
|
108
128
|
it 'should return an instance of [SugarCube::Anonymous, SugarCube::AnonymousArray]' do
|
109
129
|
a = @h.map{|k,v| v.class}
|
110
130
|
a[0].should == SugarCube::Anonymous
|
111
131
|
a[1].should == SugarCube::AnonymousArray
|
112
132
|
end
|
113
|
-
|
133
|
+
|
114
134
|
end
|
115
|
-
|
135
|
+
|
116
136
|
describe "collect" do
|
117
|
-
|
137
|
+
|
118
138
|
it 'should return an instance of [SugarCube::Anonymous, SugarCube::AnonymousArray]' do
|
119
139
|
a = @h.collect{|k,v| v.class}
|
120
140
|
a[0].should == SugarCube::Anonymous
|
@@ -122,98 +142,98 @@ describe "SugarCube::Anonymous nested case" do
|
|
122
142
|
end
|
123
143
|
|
124
144
|
end
|
125
|
-
|
145
|
+
|
126
146
|
end
|
127
|
-
|
147
|
+
|
128
148
|
end
|
129
149
|
|
130
150
|
describe "array" do
|
131
|
-
|
151
|
+
|
132
152
|
it 'should return an instance of SugarCube::AnonymousArray' do
|
133
153
|
@h.array.class.should == SugarCube::AnonymousArray
|
134
154
|
end
|
135
|
-
|
155
|
+
|
136
156
|
it 'should not copy again' do
|
137
157
|
@h.array.object_id.should == @h.array.object_id
|
138
158
|
end
|
139
|
-
|
159
|
+
|
140
160
|
describe "inner object" do
|
141
|
-
|
161
|
+
|
142
162
|
it 'should return an instance of SugarCube::Anonymous' do
|
143
163
|
@h.array[0].class.should == SugarCube::Anonymous
|
144
164
|
end
|
145
|
-
|
165
|
+
|
146
166
|
it 'should return an instance of SugarCube::Anonymous' do
|
147
167
|
@h.array.first.class.should == SugarCube::Anonymous
|
148
168
|
end
|
149
|
-
|
169
|
+
|
150
170
|
it 'should return an instance of SugarCube::AnonymousArray' do
|
151
171
|
@h.array[1].class.should == SugarCube::AnonymousArray
|
152
172
|
end
|
153
|
-
|
173
|
+
|
154
174
|
it 'should return an instance of SugarCube::AnonymousArray' do
|
155
175
|
@h.array.last.class.should == SugarCube::AnonymousArray
|
156
176
|
end
|
157
|
-
|
177
|
+
|
158
178
|
end
|
159
|
-
|
179
|
+
|
160
180
|
describe "Enumerable" do
|
161
181
|
|
162
182
|
describe "each" do
|
163
|
-
|
183
|
+
|
164
184
|
it 'should return an instance of [SugarCube::Anonymous, SugarCube::AnonymousArray]' do
|
165
185
|
a = []
|
166
186
|
@h.array.each{|e| a << e.class}
|
167
187
|
a[0].should == SugarCube::Anonymous
|
168
188
|
a[1].should == SugarCube::AnonymousArray
|
169
189
|
end
|
170
|
-
|
190
|
+
|
171
191
|
end
|
172
|
-
|
192
|
+
|
173
193
|
describe "each_with_index" do
|
174
|
-
|
194
|
+
|
175
195
|
it 'should return an instance of [0,1]' do
|
176
196
|
a = []
|
177
197
|
@h.array.each_with_index{|e,i| a << i}
|
178
198
|
a.should == [0,1]
|
179
199
|
end
|
180
|
-
|
200
|
+
|
181
201
|
end
|
182
|
-
|
202
|
+
|
183
203
|
describe "map" do
|
184
|
-
|
204
|
+
|
185
205
|
it 'should return an instance of [SugarCube::Anonymous, SugarCube::AnonymousArray]' do
|
186
206
|
a = @h.array.map{|e| e.class}
|
187
207
|
a[0].should == SugarCube::Anonymous
|
188
208
|
a[1].should == SugarCube::AnonymousArray
|
189
209
|
end
|
190
|
-
|
210
|
+
|
191
211
|
end
|
192
|
-
|
212
|
+
|
193
213
|
describe "collect" do
|
194
|
-
|
214
|
+
|
195
215
|
it 'should return an instance of [SugarCube::Anonymous, SugarCube::AnonymousArray]' do
|
196
216
|
a = @h.array.collect{|e| e.class}
|
197
217
|
a[0].should == SugarCube::Anonymous
|
198
218
|
a[1].should == SugarCube::AnonymousArray
|
199
219
|
end
|
200
|
-
|
220
|
+
|
201
221
|
end
|
202
|
-
|
222
|
+
|
203
223
|
describe "find" do
|
204
|
-
|
224
|
+
|
205
225
|
it 'should return then first object' do
|
206
226
|
r = @h.array.find{|e| e.is_a? Hash}
|
207
227
|
r.should == @h.array[0]
|
208
228
|
end
|
209
|
-
|
229
|
+
|
210
230
|
it 'should return the second object' do
|
211
231
|
r = @h.array.find{|e| e.is_a? Array}
|
212
232
|
r.should == @h.array[1]
|
213
233
|
end
|
214
|
-
|
234
|
+
|
215
235
|
end
|
216
|
-
|
236
|
+
|
217
237
|
end
|
218
238
|
|
219
239
|
end
|
data/spec/date_parser_spec.rb
CHANGED
@@ -7,7 +7,12 @@ describe "Base Methods" do
|
|
7
7
|
t.hour.should == 19
|
8
8
|
t.min.should == 30
|
9
9
|
t.sec.should == 0
|
10
|
-
|
10
|
+
|
11
|
+
if (today + 1.day).day == 1
|
12
|
+
t.day.should == 1
|
13
|
+
else
|
14
|
+
(t.day - today.day).should == 1
|
15
|
+
end
|
11
16
|
end
|
12
17
|
|
13
18
|
it "parses a specific natural language string, returning a date" do
|
data/spec/image_scale_spec.rb
CHANGED
@@ -5,42 +5,42 @@ describe "UIImage scale methods" do
|
|
5
5
|
|
6
6
|
it 'should scale_to a wider size' do
|
7
7
|
scaled = @image.scale_to([20, 10])
|
8
|
-
scaled.nsdata.writeToFile('scale_to.png'.
|
8
|
+
scaled.nsdata.writeToFile('scale_to.png'.document_path, atomically: true)
|
9
9
|
scaled.size.width.should == 20
|
10
10
|
scaled.size.height.should == 10
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should scale_to a taller size' do
|
14
14
|
scaled = @image.scale_to([10, 20])
|
15
|
-
scaled.nsdata.writeToFile('scale_to.png'.
|
15
|
+
scaled.nsdata.writeToFile('scale_to.png'.document_path, atomically: true)
|
16
16
|
scaled.size.width.should == 10
|
17
17
|
scaled.size.height.should == 20
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'scale_to should support background' do
|
21
21
|
scaled = @image.scale_to([20, 10], background: :blue.uicolor)
|
22
|
-
scaled.nsdata.writeToFile('scale_to_background.png'.
|
22
|
+
scaled.nsdata.writeToFile('scale_to_background.png'.document_path, atomically: true)
|
23
23
|
scaled.size.width.should == 20
|
24
24
|
scaled.size.height.should == 10
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'should scale_within a smaller size' do
|
28
28
|
scaled = @image.scale_within([5, 10])
|
29
|
-
scaled.nsdata.writeToFile('scale_within_smaller.png'.
|
29
|
+
scaled.nsdata.writeToFile('scale_within_smaller.png'.document_path, atomically: true)
|
30
30
|
scaled.size.width.should == 5
|
31
31
|
scaled.size.height.should == 5
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'should scale_within a bigger size' do
|
35
35
|
scaled = @image.scale_within([15, 20])
|
36
|
-
scaled.nsdata.writeToFile('scale_within_bigger.png'.
|
36
|
+
scaled.nsdata.writeToFile('scale_within_bigger.png'.document_path, atomically: true)
|
37
37
|
scaled.size.width.should == 15
|
38
38
|
scaled.size.height.should == 15
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'should scale_to_fill a wider size' do
|
42
42
|
scaled = @image.scale_to_fill([20, 10])
|
43
|
-
scaled.nsdata.writeToFile('scale_to_fill_wider.png'.
|
43
|
+
scaled.nsdata.writeToFile('scale_to_fill_wider.png'.document_path, atomically: true)
|
44
44
|
scaled.size.width.should == 20
|
45
45
|
scaled.size.height.should == 10
|
46
46
|
scaled.scale.should == @image.scale
|
@@ -48,7 +48,7 @@ describe "UIImage scale methods" do
|
|
48
48
|
|
49
49
|
it 'should scale_to_fill a smaller size' do
|
50
50
|
scaled = @image.scale_to_fill([5, 5])
|
51
|
-
scaled.nsdata.writeToFile('scale_to_fill_smaller.png'.
|
51
|
+
scaled.nsdata.writeToFile('scale_to_fill_smaller.png'.document_path, atomically: true)
|
52
52
|
scaled.size.width.should == 5
|
53
53
|
scaled.size.height.should == 5
|
54
54
|
scaled.scale.should == @image.scale
|
@@ -56,23 +56,23 @@ describe "UIImage scale methods" do
|
|
56
56
|
|
57
57
|
it 'scale_to_fill should support position' do
|
58
58
|
scaled = @image.scale_to_fill([10, 20], position: :top_left)
|
59
|
-
scaled.nsdata.writeToFile('scale_to_fill_position_top_left.png'.
|
59
|
+
scaled.nsdata.writeToFile('scale_to_fill_position_top_left.png'.document_path, atomically: true)
|
60
60
|
scaled = @image.scale_to_fill([20, 10], position: :top)
|
61
|
-
scaled.nsdata.writeToFile('scale_to_fill_position_top.png'.
|
61
|
+
scaled.nsdata.writeToFile('scale_to_fill_position_top.png'.document_path, atomically: true)
|
62
62
|
scaled = @image.scale_to_fill([10, 20], position: :top_right)
|
63
|
-
scaled.nsdata.writeToFile('scale_to_fill_position_top_right.png'.
|
63
|
+
scaled.nsdata.writeToFile('scale_to_fill_position_top_right.png'.document_path, atomically: true)
|
64
64
|
scaled = @image.scale_to_fill([10, 20], position: :left)
|
65
|
-
scaled.nsdata.writeToFile('scale_to_fill_position_left.png'.
|
65
|
+
scaled.nsdata.writeToFile('scale_to_fill_position_left.png'.document_path, atomically: true)
|
66
66
|
scaled = @image.scale_to_fill([20, 10], position: :center)
|
67
|
-
scaled.nsdata.writeToFile('scale_to_fill_position_center.png'.
|
67
|
+
scaled.nsdata.writeToFile('scale_to_fill_position_center.png'.document_path, atomically: true)
|
68
68
|
scaled = @image.scale_to_fill([10, 20], position: :right)
|
69
|
-
scaled.nsdata.writeToFile('scale_to_fill_position_right.png'.
|
69
|
+
scaled.nsdata.writeToFile('scale_to_fill_position_right.png'.document_path, atomically: true)
|
70
70
|
scaled = @image.scale_to_fill([10, 20], position: :bottom_left)
|
71
|
-
scaled.nsdata.writeToFile('scale_to_fill_position_bottom_left.png'.
|
71
|
+
scaled.nsdata.writeToFile('scale_to_fill_position_bottom_left.png'.document_path, atomically: true)
|
72
72
|
scaled = @image.scale_to_fill([20, 10], position: :bottom)
|
73
|
-
scaled.nsdata.writeToFile('scale_to_fill_position_bottom.png'.
|
73
|
+
scaled.nsdata.writeToFile('scale_to_fill_position_bottom.png'.document_path, atomically: true)
|
74
74
|
scaled = @image.scale_to_fill([10, 20], position: :bottom_right)
|
75
|
-
scaled.nsdata.writeToFile('scale_to_fill_position_bottom_right.png'.
|
75
|
+
scaled.nsdata.writeToFile('scale_to_fill_position_bottom_right.png'.document_path, atomically: true)
|
76
76
|
scaled.size.width.should == 10
|
77
77
|
scaled.size.height.should == 20
|
78
78
|
end
|
@@ -80,14 +80,14 @@ describe "UIImage scale methods" do
|
|
80
80
|
it 'should be able to change scale' do
|
81
81
|
if UIScreen.mainScreen.scale == 2
|
82
82
|
scaled = @image.at_scale(1.0)
|
83
|
-
scaled.nsdata.writeToFile('at_scale.png'.
|
83
|
+
scaled.nsdata.writeToFile('at_scale.png'.document_path, atomically: true)
|
84
84
|
|
85
85
|
scaled.size.width.should == 20
|
86
86
|
scaled.size.height.should == 20
|
87
87
|
scaled.scale.should == 1
|
88
88
|
else
|
89
89
|
scaled = @image.at_scale(2.0)
|
90
|
-
scaled.nsdata.writeToFile('at_scale.png'.
|
90
|
+
scaled.nsdata.writeToFile('at_scale.png'.document_path, atomically: true)
|
91
91
|
|
92
92
|
scaled.size.width.should == 5
|
93
93
|
scaled.size.height.should == 5
|
data/spec/nsstring_files_spec.rb
CHANGED
@@ -50,11 +50,11 @@ describe 'NSString' do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should not file_exists" do
|
53
|
-
"abc".
|
53
|
+
"abc".cache_path.file_exists?.should == false
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should not file_exists" do
|
57
|
-
"abc".
|
57
|
+
"abc".resource_path.file_exists?.should == false
|
58
58
|
end
|
59
59
|
|
60
60
|
describe "in document" do
|
@@ -85,7 +85,7 @@ describe 'NSString' do
|
|
85
85
|
|
86
86
|
describe "in resource" do
|
87
87
|
it "should be file_exists" do
|
88
|
-
"info.plist".
|
88
|
+
"info.plist".resource_path.file_exists?.should == true
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sugarcube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2014-01-
|
15
|
+
date: 2014-01-31 00:00:00.000000000 Z
|
16
16
|
dependencies: []
|
17
17
|
description: ! '== Description
|
18
18
|
|