sugarcube 0.15.0 → 0.15.3
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/README.md +86 -13
- data/lib/sugarcube/adjust.rb +10 -7
- data/lib/sugarcube/fixnum.rb +10 -2
- data/lib/sugarcube/nsdate.rb +4 -4
- data/lib/sugarcube/nsdate_delta.rb +6 -3
- data/lib/sugarcube/numeric.rb +32 -3
- data/lib/sugarcube/symbol.rb +46 -0
- data/lib/sugarcube/uiview.rb +10 -0
- data/lib/sugarcube/version.rb +1 -1
- data/runtests +1 -0
- data/spec/core_location_spec.rb +2 -2
- data/spec/date_delta_spec.rb +103 -0
- data/spec/fixnum_spec.rb +121 -0
- data/spec/notification_spec.rb +54 -0
- data/spec/nsarray_spec.rb +46 -0
- data/spec/nscoder_spec.rb +75 -0
- data/spec/numeric_spec.rb +83 -0
- data/spec/symbol_uicolor_spec.rb +0 -2
- data/spec/uiview_spec.rb +11 -0
- metadata +17 -3
- data/lib/sugarcube/defaults.rb +0 -47
data/README.md
CHANGED
@@ -94,7 +94,12 @@ Examples
|
|
94
94
|
|
95
95
|
NSDate.new # => 2013-01-03 11:42:24 -0700
|
96
96
|
5.days.ago # => 2012-12-29 11:42:24 -0700
|
97
|
+
5.days.before(NSDate.new) # => 2012-12-29 11:42:24 -0700
|
97
98
|
5.days.hence # => 2013-01-08 11:42:24 -0700
|
99
|
+
5.days.after(NSDate.new) # => 2013-01-08 11:42:24 -0700
|
100
|
+
# don't confuse 'after' and 'later'
|
101
|
+
# after => NSDate
|
102
|
+
# later => NSTimer
|
98
103
|
```
|
99
104
|
|
100
105
|
Numeric
|
@@ -117,6 +122,11 @@ NSDate.new # => 2013-01-03 11:42:24 -0700
|
|
117
122
|
distance = 1500 # this is in meters. why? because all the methods that return
|
118
123
|
# a "distance" return it in meters
|
119
124
|
distance.miles # => 0.932056427001953
|
125
|
+
|
126
|
+
# use NSNumberFormatter to easily format a number in the current locale
|
127
|
+
10000.string_with_style # => "10,000"
|
128
|
+
10000.string_with_style(NSNumberFormatterCurrencyStyle) # => "$10,000.00"
|
129
|
+
10000.string_with_style(:currency) # => "$10,000.00"
|
120
130
|
```
|
121
131
|
|
122
132
|
NSCoder
|
@@ -195,20 +205,74 @@ recurring events)
|
|
195
205
|
<http://www.unicode.org/reports/tr35/tr35-25.html#Date_Format_Patterns> for
|
196
206
|
the formatters, they take getting used to, coming from `strftime`, but they
|
197
207
|
are much more powerful and locale-aware.
|
208
|
+
5. Misc other helpers. I'll go over these first.
|
198
209
|
|
199
|
-
|
210
|
+
###### Helpers
|
211
|
+
|
212
|
+
```ruby
|
200
213
|
(main)> now = NSDate.new # Time.new is the same thing
|
201
214
|
=> 2012-09-13 09:19:06 -0600
|
215
|
+
|
216
|
+
# NSDate##from_components
|
217
|
+
(main)> feb_1_2013 = NSDate.from_components(year: 2013, month: 2, day:1)
|
218
|
+
=> 2013-02-01 00:00:00 -0700
|
219
|
+
(main)> feb_1_2013_sometime_later = NSDate.from_components(year: 2013, month: 2, day:1, hour:13, minute: 59, second:30)
|
220
|
+
=> 2013-02-01 13:59:30 -0700
|
221
|
+
(main)> feb_1_2012 = NSDate.from_components(year: 2012, month: 2, day:1)
|
222
|
+
=> 2012-02-01 00:00:00 -0700
|
223
|
+
|
224
|
+
|
225
|
+
(main)> feb_1_2013.timezone.name
|
226
|
+
=> "America/Denver"
|
227
|
+
(main)> feb_1_2013.era
|
228
|
+
=> 1 # no, I don't know what this is :-/
|
229
|
+
(main)> feb_1_2013.today?
|
230
|
+
=> false # actually, at the time i'm WRITING this, it IS true, but by the time
|
231
|
+
# you read it, not so much ;-)
|
232
|
+
(main)> NSDate.new.today?
|
233
|
+
=> true
|
234
|
+
(main)> feb_1_2013.same_day?(NSDate.new)
|
235
|
+
=> false
|
236
|
+
(main)> feb_1_2013.same_day?(feb_1_2013_sometime_later)
|
237
|
+
# even though the time is different!?
|
238
|
+
=> true
|
239
|
+
(main)> feb_1_2013.utc_offset
|
240
|
+
=> -25200
|
241
|
+
(main)> feb_1_2013.leap_year?
|
242
|
+
=> false
|
243
|
+
(main)> NSDate.from_components(year: 2012).leap_year?
|
244
|
+
=> true
|
245
|
+
(main)> feb_1_2013.start_of_day
|
246
|
+
=> 2013-02-01 00:00:00 -0700
|
247
|
+
(main)> feb_1_2013.end_of_day
|
248
|
+
# NOTE! end_of_day is the NEXT DAY. this is not an accident, it makes comparisons cleaner. deal with it.
|
249
|
+
=> 2013-02-02 00:00:00 -0700
|
250
|
+
(main)> feb_1_2013.days_in_month
|
251
|
+
=> 28
|
252
|
+
(main)> feb_1_2013.days_in_year
|
253
|
+
=> 365
|
254
|
+
(main)> feb_1_2012.days_in_month
|
255
|
+
=> 29
|
256
|
+
(main)> feb_1_2012.days_in_year
|
257
|
+
=> 366
|
258
|
+
|
202
259
|
(main)> now.date_array
|
203
260
|
=> [2012, 9, 13]
|
204
261
|
(main)> now.time_array
|
205
262
|
=> [9, 19, 6]
|
206
263
|
(main)> now.datetime_array
|
207
264
|
=> [2012, 9, 13, 9, 19, 6]
|
265
|
+
|
266
|
+
(main)> now.string_with_style
|
267
|
+
=> "Tuesday, January 29, 2013"
|
268
|
+
(main)> now.string_with_style(NSDateFormatterShortStyle)
|
269
|
+
=> "1/29/13"
|
270
|
+
(main)> now.string_with_style(:short)
|
271
|
+
=> "1/29/13"
|
208
272
|
```
|
209
273
|
|
210
|
-
|
211
|
-
|
274
|
+
It is easy to add seconds to the date using the time-related methods added to
|
275
|
+
`Numeric`, thought the `NSDate#delta` method is MUCH more capable.
|
212
276
|
|
213
277
|
```ruby
|
214
278
|
(main)> now + 5
|
@@ -219,15 +283,12 @@ to `Numeric`, and the useful `start_of_day`/`end_of_day` methods.
|
|
219
283
|
=> 2012-09-13 09:24:06 -0600
|
220
284
|
(main)> now + 5.days
|
221
285
|
=> 2012-09-18 09:19:06 -0600
|
222
|
-
(main)> now.start_of_day
|
223
|
-
=> 2012-09-13 00:00:00 -0600
|
224
|
-
(main)> now.end_of_day
|
225
|
-
=> 2012-09-14 00:00:00 -0600
|
226
286
|
```
|
227
287
|
|
228
288
|
Time zone objects are available, but the `Time#utc_offset` method is a little
|
229
289
|
more useful. It returns the offset *in seconds*, so divide by `1.0.hour` to get
|
230
|
-
the offset in hours. `utc_offset` is built into `Time`, not added by SugarCube
|
290
|
+
the offset in hours. `utc_offset` is built into `Time`, not added by SugarCube,
|
291
|
+
but it is added to the `NSDate` class in case you get one of those instead.
|
231
292
|
|
232
293
|
```ruby
|
233
294
|
(main)> now.timezone
|
@@ -240,10 +301,12 @@ the offset in hours. `utc_offset` is built into `Time`, not added by SugarCube.
|
|
240
301
|
=> -6
|
241
302
|
```
|
242
303
|
|
243
|
-
The `delta` method is smart.
|
304
|
+
The `delta` method is smart. See the tests! It will do its best to compensate
|
305
|
+
for daylight savings, leap years, different numbers of days in the month, and so
|
306
|
+
on.
|
244
307
|
|
245
308
|
```ruby
|
246
|
-
(main)> feb_28_2012 =
|
309
|
+
(main)> feb_28_2012 = NSDate.from_components(year:2012, month: 2, day: 28)
|
247
310
|
=> 2012-02-28 17:00:00 -0700
|
248
311
|
|
249
312
|
# add an hour or two
|
@@ -260,7 +323,7 @@ The `delta` method is smart.
|
|
260
323
|
|
261
324
|
# how about a month?
|
262
325
|
(main)> feb_28_2012.delta(months:1)
|
263
|
-
=> 2012-03-28 17:00:00 -0600 # look, the time didn't change, event though there was a DST change!
|
326
|
+
=> 2012-03-28 17:00:00 -0600 # look, the time didn't change, event though there was a DST change in this period!
|
264
327
|
|
265
328
|
# cool, but if you want a more literal "24 hours", specify a time unit
|
266
329
|
(main)> feb_28_2012.delta(months:1, hours:0)
|
@@ -317,6 +380,9 @@ The `delta` method is smart.
|
|
317
380
|
=> 2012-02-29 17:00:00 -0700
|
318
381
|
# ...ck yeah! :-)
|
319
382
|
|
383
|
+
# daylight savings!? GEEZ dates are annoying
|
384
|
+
(main)> mar_10_2013 = NSDate.from_components
|
385
|
+
|
320
386
|
# unfortunately you will, in the edge cases, end up with stuff like this:
|
321
387
|
(main)> feb_28_2012 == feb_28_2012.delta(days:1, months:12).delta(months:-12)
|
322
388
|
=> true
|
@@ -491,15 +557,19 @@ image.stretchable(insets)
|
|
491
557
|
# Apply a mask to an image. The mask should be a grayscale image. White areas
|
492
558
|
# will be made transparent, and black opaque.
|
493
559
|
image.masked(mask_image)
|
560
|
+
|
561
|
+
# Combine two images
|
562
|
+
image_ab = image_a << image_b
|
494
563
|
```
|
495
564
|
|
496
565
|
#### 568
|
497
566
|
|
498
567
|
If you `require 'sugarcube-568'` in your Rakefile, you can use
|
499
|
-
`UIImage.imageNamed()` to load images that are specific to
|
568
|
+
`UIImage.imageNamed(name)` or `name.uiimage` to load images that are specific to
|
569
|
+
the 4" iphone.
|
500
570
|
|
501
571
|
```ruby
|
502
|
-
'tall'.uiimage
|
572
|
+
'tall'.uiimage # => UIImage.imageNamed('tall')
|
503
573
|
# => tall.png on iphone 3g
|
504
574
|
# => tall@2x.png on iphone 4
|
505
575
|
# => tall-568h@2x.png on iphone 5
|
@@ -572,6 +642,9 @@ my_view.controller # => returns the UIViewController that this view belongs to
|
|
572
642
|
self.view << subview # => self.view.addSubview(subview)
|
573
643
|
self.view.show # => self.hidden = false
|
574
644
|
self.view.hide # => self.hidden = true
|
645
|
+
|
646
|
+
# convert to UIImage. retina-ready.
|
647
|
+
my_view.uiimage
|
575
648
|
```
|
576
649
|
|
577
650
|
###### Animations
|
data/lib/sugarcube/adjust.rb
CHANGED
@@ -47,8 +47,9 @@ module SugarCube
|
|
47
47
|
def frame f=nil
|
48
48
|
raise "no view has been assigned to SugarCube::Adjust::adjust" unless $sugarcube_view
|
49
49
|
|
50
|
-
return
|
50
|
+
return $sugarcube_view.frame if not f
|
51
51
|
|
52
|
+
f = SugarCube::CoreGraphics::Rect(f)
|
52
53
|
$sugarcube_view.frame = f
|
53
54
|
puts format_frame(f)
|
54
55
|
|
@@ -95,13 +96,13 @@ module SugarCube
|
|
95
96
|
raise "no view has been assigned to SugarCube::Adjust::adjust" unless $sugarcube_view
|
96
97
|
|
97
98
|
f = $sugarcube_view.frame
|
98
|
-
return
|
99
|
+
return f.origin if not x
|
99
100
|
|
100
101
|
if y
|
101
102
|
f.origin.x = x
|
102
103
|
f.origin.y = y
|
103
104
|
else
|
104
|
-
f.origin = x
|
105
|
+
f.origin = SugarCube::CoreGraphics::Point(x)
|
105
106
|
end
|
106
107
|
$sugarcube_view.frame = f
|
107
108
|
puts format_frame(f)
|
@@ -149,13 +150,13 @@ module SugarCube
|
|
149
150
|
raise "no view has been assigned to SugarCube::Adjust::adjust" unless $sugarcube_view
|
150
151
|
|
151
152
|
f = $sugarcube_view.frame
|
152
|
-
return
|
153
|
+
return f.size if not w
|
153
154
|
|
154
155
|
if h
|
155
156
|
f.size.width = w
|
156
157
|
f.size.height = h
|
157
158
|
else
|
158
|
-
f.size = w
|
159
|
+
f.size = SugarCube::CoreGraphics::Size(w)
|
159
160
|
end
|
160
161
|
$sugarcube_view.frame = f
|
161
162
|
puts format_frame(f)
|
@@ -376,8 +377,10 @@ module SugarCube
|
|
376
377
|
|
377
378
|
def format_frame(frame)
|
378
379
|
case SugarCube::Adjust::repl_format
|
379
|
-
when :json then
|
380
|
-
|
380
|
+
when :json then
|
381
|
+
"{x: #{frame.origin.x}, y: #{frame.origin.y}, width: #{frame.size.width}, height: #{frame.size.height}}"
|
382
|
+
when :ruby then
|
383
|
+
"[[#{frame.origin.x}, #{frame.origin.y}], [#{frame.size.width}, #{frame.size.height}]]"
|
381
384
|
when :objc
|
382
385
|
frame.to_s
|
383
386
|
else
|
data/lib/sugarcube/fixnum.rb
CHANGED
@@ -32,12 +32,20 @@ class Fixnum
|
|
32
32
|
return "th"
|
33
33
|
end
|
34
34
|
|
35
|
+
def before(date)
|
36
|
+
date - self
|
37
|
+
end
|
38
|
+
|
35
39
|
def ago
|
36
|
-
NSDate.new
|
40
|
+
self.before(NSDate.new)
|
41
|
+
end
|
42
|
+
|
43
|
+
def after(date)
|
44
|
+
date + self
|
37
45
|
end
|
38
46
|
|
39
47
|
def hence
|
40
|
-
NSDate.new
|
48
|
+
self.after(NSDate.new)
|
41
49
|
end
|
42
50
|
|
43
51
|
end
|
data/lib/sugarcube/nsdate.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
class NSDate
|
2
2
|
|
3
3
|
def self.from_components(components)
|
4
|
-
|
4
|
+
date_components = NSDateComponents.new
|
5
5
|
components.each do |property,value|
|
6
|
-
|
6
|
+
date_components.send("#{property}=", value)
|
7
7
|
end
|
8
8
|
calendar = NSCalendar.alloc.initWithCalendarIdentifier(NSGregorianCalendar)
|
9
|
-
return calendar.dateFromComponents(
|
9
|
+
return calendar.dateFromComponents(date_components)
|
10
10
|
end
|
11
11
|
|
12
12
|
def string_with_style(style)
|
@@ -105,7 +105,7 @@ class NSDate
|
|
105
105
|
end
|
106
106
|
|
107
107
|
def days_in_year
|
108
|
-
|
108
|
+
leap_year? ? 366 : 365
|
109
109
|
end
|
110
110
|
|
111
111
|
private
|
@@ -22,8 +22,6 @@ class NSDate
|
|
22
22
|
delta += mi.minutes
|
23
23
|
delta += h.hours
|
24
24
|
|
25
|
-
delta += d.days
|
26
|
-
delta += w.weeks
|
27
25
|
return_date = self + delta
|
28
26
|
|
29
27
|
# using days_in_month, this is pretty easy. 12 mos per year IS a constant,
|
@@ -58,7 +56,7 @@ class NSDate
|
|
58
56
|
end
|
59
57
|
end
|
60
58
|
end
|
61
|
-
|
59
|
+
else # mo < 0
|
62
60
|
(-mo).times do
|
63
61
|
# subtract *last* months number of days.
|
64
62
|
# there is a REALLY rare case where subtracting return_date.day is one
|
@@ -80,6 +78,11 @@ class NSDate
|
|
80
78
|
end
|
81
79
|
end
|
82
80
|
|
81
|
+
delta = 0
|
82
|
+
delta += d.days
|
83
|
+
delta += w.weeks
|
84
|
+
return_date += delta
|
85
|
+
|
83
86
|
# DST adjustment, unless minutes, hours, or seconds were specified.
|
84
87
|
#
|
85
88
|
# the thinking here is that if they WERE specified, the delta should be
|
data/lib/sugarcube/numeric.rb
CHANGED
@@ -7,10 +7,12 @@ class Numeric
|
|
7
7
|
def radians
|
8
8
|
self
|
9
9
|
end
|
10
|
+
alias radian radians
|
10
11
|
|
11
12
|
def degrees
|
12
13
|
self / 180.0 * Math::PI
|
13
14
|
end
|
15
|
+
alias degree degrees
|
14
16
|
|
15
17
|
def pi
|
16
18
|
self * Math::PI
|
@@ -19,17 +21,44 @@ class Numeric
|
|
19
21
|
def meters
|
20
22
|
self
|
21
23
|
end
|
24
|
+
alias meter meters
|
25
|
+
|
26
|
+
def in_meters
|
27
|
+
self
|
28
|
+
end
|
22
29
|
|
23
30
|
def kilometers
|
24
|
-
self
|
31
|
+
self * 1000.0
|
32
|
+
end
|
33
|
+
alias kilometer kilometers
|
34
|
+
|
35
|
+
def in_kilometers
|
36
|
+
self / 1.kilometer
|
25
37
|
end
|
26
38
|
|
27
39
|
def miles
|
28
|
-
self *
|
40
|
+
self * 1609.344
|
41
|
+
end
|
42
|
+
alias mile miles
|
43
|
+
|
44
|
+
def in_miles
|
45
|
+
self / 1.mile
|
29
46
|
end
|
30
47
|
|
31
48
|
def feet
|
32
|
-
self
|
49
|
+
self / 3.28084
|
50
|
+
end
|
51
|
+
alias foot feet
|
52
|
+
|
53
|
+
def in_feet
|
54
|
+
self / 1.foot
|
55
|
+
end
|
56
|
+
|
57
|
+
def string_with_style(style=NSNumberFormatterDecimalStyle)
|
58
|
+
if style.is_a? Symbol
|
59
|
+
style = style.nsnumberstyle
|
60
|
+
end
|
61
|
+
NSNumberFormatter.localizedStringFromNumber(self, numberStyle:style)
|
33
62
|
end
|
34
63
|
|
35
64
|
end
|
data/lib/sugarcube/symbol.rb
CHANGED
@@ -26,6 +26,8 @@ class Symbol
|
|
26
26
|
class << self
|
27
27
|
attr_accessor :devices
|
28
28
|
attr_accessor :device_orientations
|
29
|
+
attr_accessor :interface_orientations
|
30
|
+
attr_accessor :interface_masks
|
29
31
|
attr_accessor :orientations
|
30
32
|
attr_accessor :returnkeys
|
31
33
|
attr_accessor :statusbar_styles
|
@@ -40,6 +42,7 @@ class Symbol
|
|
40
42
|
attr_accessor :system_fonts
|
41
43
|
attr_accessor :font_sizes
|
42
44
|
attr_accessor :date_styles
|
45
|
+
attr_accessor :number_styles
|
43
46
|
|
44
47
|
attr_accessor :buttontypes
|
45
48
|
attr_accessor :border_types
|
@@ -85,6 +88,25 @@ class Symbol
|
|
85
88
|
face_down: UIDeviceOrientationFaceDown
|
86
89
|
}
|
87
90
|
|
91
|
+
@interface_orientations = {
|
92
|
+
portrait: UIInterfaceOrientationPortrait,
|
93
|
+
upside_down: UIInterfaceOrientationPortraitUpsideDown,
|
94
|
+
left: UIInterfaceOrientationLandscapeLeft,
|
95
|
+
right: UIInterfaceOrientationLandscapeRight,
|
96
|
+
}
|
97
|
+
|
98
|
+
@interface_masks = {
|
99
|
+
portrait: UIInterfaceOrientationMaskPortrait,
|
100
|
+
landscrape: UIInterfaceOrientationMaskLandscape,
|
101
|
+
left: UIInterfaceOrientationMaskLandscapeLeft,
|
102
|
+
right: UIInterfaceOrientationMaskLandscapeRight,
|
103
|
+
upside_down: UIInterfaceOrientationMaskPortraitUpsideDown,
|
104
|
+
all_but_upside_down: UIInterfaceOrientationMaskAllButUpsideDown,
|
105
|
+
iphone: UIInterfaceOrientationMaskAllButUpsideDown,
|
106
|
+
all: UIInterfaceOrientationMaskAll,
|
107
|
+
ipad: UIInterfaceOrientationMaskAll,
|
108
|
+
}
|
109
|
+
|
88
110
|
@textalignments = {
|
89
111
|
left: UITextAlignmentLeft,
|
90
112
|
right: UITextAlignmentRight,
|
@@ -203,6 +225,17 @@ class Symbol
|
|
203
225
|
full: NSDateFormatterFullStyle,
|
204
226
|
}
|
205
227
|
|
228
|
+
@number_styles = {
|
229
|
+
no: NSNumberFormatterNoStyle,
|
230
|
+
none: NSNumberFormatterNoStyle,
|
231
|
+
decimal: NSNumberFormatterDecimalStyle,
|
232
|
+
currency: NSNumberFormatterCurrencyStyle,
|
233
|
+
percent: NSNumberFormatterPercentStyle,
|
234
|
+
scientific: NSNumberFormatterScientificStyle,
|
235
|
+
spellout: NSNumberFormatterSpellOutStyle,
|
236
|
+
spell_out: NSNumberFormatterSpellOutStyle,
|
237
|
+
}
|
238
|
+
|
206
239
|
@returnkeys = {
|
207
240
|
default: UIReturnKeyDefault,
|
208
241
|
return: UIReturnKeyDefault,
|
@@ -455,6 +488,14 @@ class Symbol
|
|
455
488
|
look_in(Symbol.device_orientations)
|
456
489
|
end
|
457
490
|
|
491
|
+
def uiinterfaceorientation
|
492
|
+
look_in(Symbol.interface_orientations)
|
493
|
+
end
|
494
|
+
|
495
|
+
def uiinterfacemask
|
496
|
+
look_in(Symbol.interface_masks)
|
497
|
+
end
|
498
|
+
|
458
499
|
def uitextalignment
|
459
500
|
look_in(Symbol.textalignments)
|
460
501
|
end
|
@@ -641,4 +682,9 @@ class Symbol
|
|
641
682
|
end
|
642
683
|
alias nsdateformatterstyle nsdatestyle
|
643
684
|
|
685
|
+
def nsnumberstyle
|
686
|
+
look_in(Symbol.number_styles)
|
687
|
+
end
|
688
|
+
alias nsnumberformatterstyle nsnumberstyle
|
689
|
+
|
644
690
|
end
|
data/lib/sugarcube/uiview.rb
CHANGED
@@ -253,4 +253,14 @@ class UIView
|
|
253
253
|
self
|
254
254
|
end
|
255
255
|
|
256
|
+
# Easily take a snapshot of a UIView
|
257
|
+
def uiimage
|
258
|
+
scale = UIScreen.mainScreen.scale
|
259
|
+
UIGraphicsBeginImageContextWithOptions(bounds.size, false, scale)
|
260
|
+
layer.renderInContext(UIGraphicsGetCurrentContext())
|
261
|
+
image = UIGraphicsGetImageFromCurrentImageContext()
|
262
|
+
UIGraphicsEndImageContext()
|
263
|
+
return image
|
264
|
+
end
|
265
|
+
|
256
266
|
end
|
data/lib/sugarcube/version.rb
CHANGED
data/runtests
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rake spec && rake spec retina=3.5 && rake spec retina=4
|
data/spec/core_location_spec.rb
CHANGED
@@ -5,11 +5,11 @@ describe "CoreLocation" do
|
|
5
5
|
end
|
6
6
|
|
7
7
|
it "should calculate distance in miles" do
|
8
|
-
@denver.distance_to(@cincinnati).
|
8
|
+
@denver.distance_to(@cincinnati).in_miles.round.should == 1101
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should calculate distance in kilometers" do
|
12
|
-
@denver.distance_to(@cincinnati).
|
12
|
+
@denver.distance_to(@cincinnati).in_kilometers.round.should == 1772
|
13
13
|
end
|
14
14
|
|
15
15
|
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
describe "NSDate#delta" do
|
2
|
+
|
3
|
+
it "should be pretty easy to add hours" do
|
4
|
+
feb_28_2012 = NSDate.from_components(year:2012, month: 2, day: 28, hour: 17)
|
5
|
+
feb_28_2012.delta(hours:1).should == NSDate.from_components(year:2012, month: 2, day: 28, hour: 18)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should be pretty easy to add minutes" do
|
9
|
+
feb_28_2012 = NSDate.from_components(year:2012, month: 2, day: 28, hour: 17, minute:10)
|
10
|
+
feb_28_2012.delta(minutes:10).should == NSDate.from_components(year:2012, month: 2, day: 28, hour: 17, minute:20)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should be easy to add minutes that change the hour" do
|
14
|
+
feb_28_2012 = NSDate.from_components(year:2012, month: 2, day: 28, hour: 17, minute:55)
|
15
|
+
feb_28_2012.delta(minutes:10).should == NSDate.from_components(year:2012, month: 2, day: 28, hour: 18, minute:5)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should be easy to add minutes that change the day" do
|
19
|
+
feb_28_2012 = NSDate.from_components(year:2012, month: 2, day: 28, hour: 23, minute:55)
|
20
|
+
feb_28_2012.delta(minutes:10).should == NSDate.from_components(year:2012, month: 2, day: 29, hour: 0, minute:5)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should be pretty easy to add seconds" do
|
24
|
+
feb_28_2012 = NSDate.from_components(year:2012, month: 2, day: 28, hour: 17, second:10)
|
25
|
+
feb_28_2012.delta(seconds:10).should == NSDate.from_components(year:2012, month: 2, day: 28, hour: 17, second:20)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be easy to add seconds that change the hour" do
|
29
|
+
feb_28_2012 = NSDate.from_components(year:2012, month: 2, day: 28, hour: 17, second:55)
|
30
|
+
feb_28_2012.delta(seconds:10).should == NSDate.from_components(year:2012, month: 2, day: 28, hour: 17, minute:1, second:5)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should be easy to add seconds that change the day" do
|
34
|
+
feb_28_2012 = NSDate.from_components(year:2012, month: 2, day: 28, hour: 23, minute:59, second:55)
|
35
|
+
feb_28_2012.delta(seconds:10).should == NSDate.from_components(year:2012, month: 2, day: 29, hour: 0, minute:0, second:5)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be easy to add a day" do
|
39
|
+
feb_28_2012 = NSDate.from_components(year:2012, month: 2, day: 28)
|
40
|
+
feb_28_2012.delta(days:1).should == NSDate.from_components(year:2012, month: 2, day: 29)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should be easy to add two days" do
|
44
|
+
feb_28_2012 = NSDate.from_components(year:2012, month: 2, day: 28)
|
45
|
+
feb_28_2012.delta(days:2).should == NSDate.from_components(year:2012, month: 3, day: 1)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should be easy to add a month" do
|
49
|
+
feb_28_2012 = NSDate.from_components(year:2012, month: 2, day: 28)
|
50
|
+
feb_28_2012.delta(months:1).should == NSDate.from_components(year:2012, month: 3, day: 28)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should be easy to add a month and a day" do
|
54
|
+
feb_28_2012 = NSDate.from_components(year:2012, month: 2, day: 28)
|
55
|
+
feb_28_2012.delta(months:1, days:1).should == NSDate.from_components(year:2012, month: 3, day: 29)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should be easy to add two months" do
|
59
|
+
feb_28_2012 = NSDate.from_components(year:2012, month: 2, day: 28)
|
60
|
+
feb_28_2012.delta(months:2).should == NSDate.from_components(year:2012, month: 4, day: 28)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should be easy to add 11 months" do
|
64
|
+
feb_28_2012 = NSDate.from_components(year:2012, month: 2, day: 28)
|
65
|
+
feb_28_2012.delta(months:11).should == NSDate.from_components(year:2013, month: 1, day: 28)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should be easy to add 11 months and 3 days" do
|
69
|
+
feb_28_2012 = NSDate.from_components(year:2012, month: 2, day: 28)
|
70
|
+
feb_28_2012.delta(months:11, days:3).should == NSDate.from_components(year:2013, month: 1, day: 31)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should be easy to add a year" do
|
74
|
+
feb_28_2012 = NSDate.from_components(year:2012, month: 2, day: 28)
|
75
|
+
feb_28_2012.delta(years:1).should == NSDate.from_components(year:2013, month: 2, day: 28)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should be easy to add a year and a day" do
|
79
|
+
feb_28_2012 = NSDate.from_components(year:2012, month: 2, day: 28)
|
80
|
+
feb_28_2012.delta(years:1, days:1).should == NSDate.from_components(year:2013, month: 3, day: 1)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should be easy to add four years" do
|
84
|
+
feb_28_2012 = NSDate.from_components(year:2012, month: 2, day: 28)
|
85
|
+
feb_28_2012.delta(years:4).should == NSDate.from_components(year:2016, month: 2, day: 28)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should handle daylight savings logically" do
|
89
|
+
# early hours
|
90
|
+
mar_10_2012 = NSDate.from_components(year:2013, month: 3, day: 9, hour: 1)
|
91
|
+
mar_10_2012.delta(days:1).should == NSDate.from_components(year:2013, month: 3, day: 10, hour: 1)
|
92
|
+
|
93
|
+
# late hours
|
94
|
+
mar_10_2012 = NSDate.from_components(year:2013, month: 3, day: 9, hour: 13)
|
95
|
+
mar_10_2012.delta(days:1).should == NSDate.from_components(year:2013, month: 3, day: 10, hour: 13)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should handle daylight savings logically unless you assign an hour" do
|
99
|
+
mar_10_2012 = NSDate.from_components(year:2013, month: 3, day: 9, hour: 13)
|
100
|
+
mar_10_2012.delta(days:1, hours: 1).should == NSDate.from_components(year:2013, month: 3, day: 10, hour: 15)
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
data/spec/fixnum_spec.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
describe "Fixnum" do
|
2
|
+
|
3
|
+
it "should have a 0xffffff#uicolor method" do
|
4
|
+
color = 0xffffff.uicolor
|
5
|
+
color.red.should == 1
|
6
|
+
color.green.should == 1
|
7
|
+
color.blue.should == 1
|
8
|
+
color.alpha.should == 1
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have a 0x000000#uicolor(0.5) method" do
|
12
|
+
color = 0.uicolor(0.5)
|
13
|
+
color.red.should == 0
|
14
|
+
color.green.should == 0
|
15
|
+
color.blue.should == 0
|
16
|
+
color.alpha.should == 0.5
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have a #nth method" do
|
20
|
+
{
|
21
|
+
0 => 'th',
|
22
|
+
1 => 'st',
|
23
|
+
2 => 'nd',
|
24
|
+
3 => 'rd',
|
25
|
+
4 => 'th',
|
26
|
+
5 => 'th',
|
27
|
+
6 => 'th',
|
28
|
+
7 => 'th',
|
29
|
+
8 => 'th',
|
30
|
+
9 => 'th',
|
31
|
+
10 => 'th',
|
32
|
+
11 => 'th',
|
33
|
+
12 => 'th',
|
34
|
+
13 => 'th',
|
35
|
+
14 => 'th',
|
36
|
+
15 => 'th',
|
37
|
+
16 => 'th',
|
38
|
+
17 => 'th',
|
39
|
+
18 => 'th',
|
40
|
+
19 => 'th',
|
41
|
+
20 => 'th',
|
42
|
+
21 => 'st',
|
43
|
+
22 => 'nd',
|
44
|
+
23 => 'rd',
|
45
|
+
24 => 'th',
|
46
|
+
25 => 'th',
|
47
|
+
26 => 'th',
|
48
|
+
27 => 'th',
|
49
|
+
28 => 'th',
|
50
|
+
29 => 'th',
|
51
|
+
30 => 'th',
|
52
|
+
31 => 'st',
|
53
|
+
32 => 'nd',
|
54
|
+
33 => 'rd',
|
55
|
+
34 => 'th',
|
56
|
+
35 => 'th',
|
57
|
+
36 => 'th',
|
58
|
+
37 => 'th',
|
59
|
+
38 => 'th',
|
60
|
+
39 => 'th',
|
61
|
+
100 => 'th',
|
62
|
+
101 => 'st',
|
63
|
+
102 => 'nd',
|
64
|
+
103 => 'rd',
|
65
|
+
104 => 'th',
|
66
|
+
105 => 'th',
|
67
|
+
106 => 'th',
|
68
|
+
107 => 'th',
|
69
|
+
108 => 'th',
|
70
|
+
109 => 'th',
|
71
|
+
110 => 'th',
|
72
|
+
111 => 'th',
|
73
|
+
112 => 'th',
|
74
|
+
113 => 'th',
|
75
|
+
114 => 'th',
|
76
|
+
115 => 'th',
|
77
|
+
116 => 'th',
|
78
|
+
117 => 'th',
|
79
|
+
118 => 'th',
|
80
|
+
119 => 'th',
|
81
|
+
2020 => 'th',
|
82
|
+
2000 => 'th',
|
83
|
+
2001 => 'st',
|
84
|
+
2002 => 'nd',
|
85
|
+
2003 => 'rd',
|
86
|
+
}.each do |num, expected|
|
87
|
+
num.nth.should == "#{expected}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should have a #before method" do
|
92
|
+
relative_to = NSDate.new
|
93
|
+
1.day.before(relative_to).should == relative_to - 1.day
|
94
|
+
2.years.before(relative_to).should == relative_to - 2.years
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should have an #after method" do
|
98
|
+
relative_to = NSDate.new
|
99
|
+
1.day.after(relative_to).should == relative_to + 1.day
|
100
|
+
2.years.after(relative_to).should == relative_to + 2.years
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should have a #ago method" do
|
104
|
+
now_a = NSDate.new - 2
|
105
|
+
now_b = NSDate.new + 2
|
106
|
+
1.day.ago.should > now_a - 1.day
|
107
|
+
1.day.ago.should < now_b - 1.day
|
108
|
+
2.years.ago.should > now_a - 2.years
|
109
|
+
2.years.ago.should < now_b - 2.years
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should have an #hence method" do
|
113
|
+
now_a = NSDate.new - 2
|
114
|
+
now_b = NSDate.new + 2
|
115
|
+
1.day.hence.should > now_a + 1.day
|
116
|
+
1.day.hence.should < now_b + 1.day
|
117
|
+
2.years.hence.should > now_a + 2.years
|
118
|
+
2.years.hence.should < now_b + 2.years
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class NotificationsTester
|
2
|
+
attr :notification
|
3
|
+
attr :object
|
4
|
+
|
5
|
+
def reset!
|
6
|
+
@notified = nil
|
7
|
+
@notification = nil
|
8
|
+
@object = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def notified?
|
12
|
+
@notified
|
13
|
+
end
|
14
|
+
|
15
|
+
def BAM(notification)
|
16
|
+
@notified = true
|
17
|
+
@notification = notification
|
18
|
+
@object = notification.object
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "Notifications" do
|
23
|
+
|
24
|
+
before do
|
25
|
+
@notification = 'NotificationName'
|
26
|
+
@object = 'specific object'
|
27
|
+
@notification_tester = NotificationsTester.new
|
28
|
+
@notification_tester_object = NotificationsTester.new
|
29
|
+
|
30
|
+
@notification.add_observer(@notification_tester, :'BAM:')
|
31
|
+
@notification.add_observer(@notification_tester_object, :'BAM:', @object)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should post and receive notification" do
|
35
|
+
@notification_tester.reset!
|
36
|
+
@notification_tester_object.reset!
|
37
|
+
|
38
|
+
@notification.post_notification
|
39
|
+
@notification_tester.notified?.should == true
|
40
|
+
@notification_tester.notification.should != nil
|
41
|
+
@notification_tester.object.should == nil
|
42
|
+
|
43
|
+
@notification.post_notification(@object)
|
44
|
+
@notification_tester_object.notified?.should == true
|
45
|
+
@notification_tester_object.notification.should != nil
|
46
|
+
@notification_tester_object.object.should == @object
|
47
|
+
end
|
48
|
+
|
49
|
+
after do
|
50
|
+
@notification.remove_observer(@notification_tester)
|
51
|
+
@notification.remove_observer(@notification_tester_object, @object)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
describe "NSArray" do
|
2
|
+
|
3
|
+
it "should have a method #to_pointer" do
|
4
|
+
pointer = [1,2,3].to_pointer(:int)
|
5
|
+
pointer.should != nil
|
6
|
+
pointer[0].should == 1
|
7
|
+
pointer[1].should == 2
|
8
|
+
pointer[2].should == 3
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have a method #nsindexpath" do
|
12
|
+
path = [0,1,2,3].nsindexpath
|
13
|
+
path.length.should == 4
|
14
|
+
path.indexAtPosition(0).should == 0
|
15
|
+
path.indexAtPosition(1).should == 1
|
16
|
+
path.indexAtPosition(2).should == 2
|
17
|
+
path.indexAtPosition(3).should == 3
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have a method #nsindexset" do
|
21
|
+
set = [0,1,2,3].nsindexset
|
22
|
+
set.count.should == 4
|
23
|
+
set.containsIndex(0).should == true
|
24
|
+
set.containsIndex(1).should == true
|
25
|
+
set.containsIndex(2).should == true
|
26
|
+
set.containsIndex(3).should == true
|
27
|
+
set.containsIndex(4).should == false
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should have a [255,255,255]#uicolor method" do
|
31
|
+
color = [255,255,255].uicolor
|
32
|
+
color.red.should == 1
|
33
|
+
color.green.should == 1
|
34
|
+
color.blue.should == 1
|
35
|
+
color.alpha.should == 1
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should have a [0, 0, 0]#uicolor(0.5) method" do
|
39
|
+
color = [0, 0, 0].uicolor(0.5)
|
40
|
+
color.red.should == 0
|
41
|
+
color.green.should == 0
|
42
|
+
color.blue.should == 0
|
43
|
+
color.alpha.should == 0.5
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
class CoderHelper
|
2
|
+
def initWithCoder(coder)
|
3
|
+
self
|
4
|
+
end
|
5
|
+
|
6
|
+
def encodeWithCoder(coder)
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
class CoderTester
|
12
|
+
attr :object
|
13
|
+
attr :bool
|
14
|
+
attr :double
|
15
|
+
attr :float
|
16
|
+
attr :int
|
17
|
+
attr :point
|
18
|
+
attr :rect
|
19
|
+
attr :size
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@object = CoderHelper.new
|
23
|
+
@bool = true
|
24
|
+
@double = 1.5
|
25
|
+
@float = 1.5
|
26
|
+
@int = 1
|
27
|
+
@point = CGPoint.new(0, 0)
|
28
|
+
@rect = CGRect.new([1, 1], [1, 1])
|
29
|
+
@size = CGSize.new(2, 2)
|
30
|
+
end
|
31
|
+
|
32
|
+
def initWithCoder(coder)
|
33
|
+
@object = coder['object']
|
34
|
+
@bool = coder.bool('bool')
|
35
|
+
@double = coder.double('double')
|
36
|
+
@float = coder.float('float')
|
37
|
+
@int = coder.int('int')
|
38
|
+
@point = coder.point('point')
|
39
|
+
@rect = coder.rect('rect')
|
40
|
+
@size = coder.size('size')
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def encodeWithCoder(coder)
|
45
|
+
coder['object'] = @object
|
46
|
+
coder.set('bool', toBool:@bool)
|
47
|
+
coder.set('double', toDouble:@double)
|
48
|
+
coder.set('float', toFloat:@float)
|
49
|
+
coder.set('int', toInt:@int)
|
50
|
+
coder.set('point', toPoint:@point)
|
51
|
+
coder.set('rect', toRect:@rect)
|
52
|
+
coder.set('size', toSize:@size)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "NSCoder" do
|
57
|
+
|
58
|
+
before do
|
59
|
+
@subject = CoderTester.new
|
60
|
+
end
|
61
|
+
|
62
|
+
it "is nscoding compliant" do
|
63
|
+
data = NSKeyedArchiver.archivedDataWithRootObject(@subject)
|
64
|
+
test = NSKeyedUnarchiver.unarchiveObjectWithData(data)
|
65
|
+
test.object.class.should == CoderHelper
|
66
|
+
test.bool.should == @subject.bool
|
67
|
+
test.double.should == @subject.double
|
68
|
+
test.float.should == @subject.float
|
69
|
+
test.int.should == @subject.int
|
70
|
+
test.point.should == @subject.point
|
71
|
+
test.rect.should == @subject.rect
|
72
|
+
test.size.should == @subject.size
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
describe "Numeric" do
|
2
|
+
|
3
|
+
it "should have a #percent method" do
|
4
|
+
0.percent.should == 0
|
5
|
+
50.percent.should == 0.50
|
6
|
+
100.percent.should == 1
|
7
|
+
200.percent.should == 2.0
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should have a #radian(s) method" do
|
11
|
+
0.radians.should == 0
|
12
|
+
1.radian.should == 1
|
13
|
+
1.5.radians.should == 1.5
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have a #degree(s) method" do
|
17
|
+
0.degrees.should == 0
|
18
|
+
1.degree.should == Math::PI / 180
|
19
|
+
180.degrees.should == Math::PI
|
20
|
+
45.degrees.should == Math::PI / 4
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have a #pi method" do
|
24
|
+
0.pi.should == 0
|
25
|
+
1.pi.should == Math::PI
|
26
|
+
2.pi.should == Math::PI * 2
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have a #meter(s) method" do
|
30
|
+
0.meters.should == 0
|
31
|
+
1.meter.should == 1
|
32
|
+
2.meters.should == 2
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have an #in_meters method" do
|
36
|
+
0.in_meters.should == 0
|
37
|
+
1.in_meters.should == 1
|
38
|
+
2.in_meters.should == 2
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should have a #kilometer(s) method" do
|
42
|
+
0.kilometers.should == 0
|
43
|
+
1.kilometer.should == 1000.meters
|
44
|
+
0.5.kilometers.should == 500.meters
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should have an #in_kilometers method" do
|
48
|
+
0.in_kilometers.should == 0
|
49
|
+
1000.meters.in_kilometers.should == 1
|
50
|
+
500.meters.in_kilometers.should == 0.5
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should have a #mile(s) method" do
|
54
|
+
0.miles.should == 0.meters
|
55
|
+
1.mile.round.should == 1609.meters
|
56
|
+
2.miles.round.should == 3219.meters
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should have an #in_miles method" do
|
60
|
+
0.meters.in_miles.should == 0
|
61
|
+
1609.meters.in_miles.round.should == 1
|
62
|
+
3219.meters.in_miles.round.should == 2
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should have a #feet(foot) method" do
|
66
|
+
0.feet.should == 0
|
67
|
+
3.foot.round.should == 1
|
68
|
+
7.feet.round.should == 2
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should have an #in_feet method" do
|
72
|
+
0.meters.in_feet.should == 0
|
73
|
+
1.meters.in_feet.round.should == 3
|
74
|
+
2.meters.in_feet.round.should == 7
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should have a #string_with_style method" do
|
78
|
+
1000.string_with_style.should == NSNumberFormatter.localizedStringFromNumber(1000, numberStyle:NSNumberFormatterDecimalStyle)
|
79
|
+
1000.string_with_style(:decimal).should == NSNumberFormatter.localizedStringFromNumber(1000, numberStyle:NSNumberFormatterDecimalStyle)
|
80
|
+
1000.string_with_style(:currency).should == NSNumberFormatter.localizedStringFromNumber(1000, numberStyle:NSNumberFormatterCurrencyStyle)
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
data/spec/symbol_uicolor_spec.rb
CHANGED
data/spec/uiview_spec.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
describe "UIView" do
|
2
|
+
|
3
|
+
it "should convert to a UIImage" do
|
4
|
+
test = UIView.alloc.initWithFrame([[0, 0], [10, 10]])
|
5
|
+
image = test.uiimage
|
6
|
+
image.class.should == UIImage
|
7
|
+
CGSizeEqualToSize(image.size, [10, 10]).should == true
|
8
|
+
image.scale.should == UIScreen.mainScreen.scale
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
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: 0.15.
|
4
|
+
version: 0.15.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2013-
|
16
|
+
date: 2013-02-02 00:00:00.000000000 Z
|
17
17
|
dependencies: []
|
18
18
|
description: ! '== Description
|
19
19
|
|
@@ -57,7 +57,6 @@ files:
|
|
57
57
|
- lib/sugarcube/calayer.rb
|
58
58
|
- lib/sugarcube/core_graphics.rb
|
59
59
|
- lib/sugarcube/core_location.rb
|
60
|
-
- lib/sugarcube/defaults.rb
|
61
60
|
- lib/sugarcube/exceptions.rb
|
62
61
|
- lib/sugarcube/fixnum.rb
|
63
62
|
- lib/sugarcube/modal.rb
|
@@ -113,16 +112,24 @@ files:
|
|
113
112
|
- resources/tall-568h@2x.png
|
114
113
|
- resources/tall.png
|
115
114
|
- resources/tall@2x.png
|
115
|
+
- runtests
|
116
116
|
- spec/568_spec.rb
|
117
117
|
- spec/calayer_spec.rb
|
118
118
|
- spec/core_graphics_spec.rb
|
119
119
|
- spec/core_location_spec.rb
|
120
|
+
- spec/date_delta_spec.rb
|
121
|
+
- spec/fixnum_spec.rb
|
122
|
+
- spec/notification_spec.rb
|
123
|
+
- spec/nsarray_spec.rb
|
124
|
+
- spec/nscoder_spec.rb
|
120
125
|
- spec/nsstring_files_spec.rb
|
126
|
+
- spec/numeric_spec.rb
|
121
127
|
- spec/symbol_uicolor_spec.rb
|
122
128
|
- spec/uicolor_components_spec.rb
|
123
129
|
- spec/uiimage_color_at_spec.rb
|
124
130
|
- spec/uiimage_scale_spec.rb
|
125
131
|
- spec/uiview_animation_spec.rb
|
132
|
+
- spec/uiview_spec.rb
|
126
133
|
- sugarcube.gemspec
|
127
134
|
homepage: https://github.com/rubymotion/sugarcube
|
128
135
|
licenses: []
|
@@ -154,10 +161,17 @@ test_files:
|
|
154
161
|
- spec/calayer_spec.rb
|
155
162
|
- spec/core_graphics_spec.rb
|
156
163
|
- spec/core_location_spec.rb
|
164
|
+
- spec/date_delta_spec.rb
|
165
|
+
- spec/fixnum_spec.rb
|
166
|
+
- spec/notification_spec.rb
|
167
|
+
- spec/nsarray_spec.rb
|
168
|
+
- spec/nscoder_spec.rb
|
157
169
|
- spec/nsstring_files_spec.rb
|
170
|
+
- spec/numeric_spec.rb
|
158
171
|
- spec/symbol_uicolor_spec.rb
|
159
172
|
- spec/uicolor_components_spec.rb
|
160
173
|
- spec/uiimage_color_at_spec.rb
|
161
174
|
- spec/uiimage_scale_spec.rb
|
162
175
|
- spec/uiview_animation_spec.rb
|
176
|
+
- spec/uiview_spec.rb
|
163
177
|
has_rdoc:
|
data/lib/sugarcube/defaults.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
class Symbol
|
2
|
-
|
3
|
-
def get_default
|
4
|
-
to_s.get_default
|
5
|
-
end
|
6
|
-
|
7
|
-
def get_default_or(default)
|
8
|
-
to_s.get_default_or(default)
|
9
|
-
end
|
10
|
-
|
11
|
-
def set_default val
|
12
|
-
to_s.set_default val
|
13
|
-
end
|
14
|
-
|
15
|
-
def remove_default
|
16
|
-
to_s.remove_default
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
class String
|
23
|
-
|
24
|
-
def get_default(default=nil)
|
25
|
-
NSUserDefaults.standardUserDefaults.objectForKey(self)
|
26
|
-
end
|
27
|
-
|
28
|
-
def get_default_or(default)
|
29
|
-
raise "Invalid default value" if default.nil?
|
30
|
-
|
31
|
-
nsdefault = self.get_default
|
32
|
-
if nsdefault.nil?
|
33
|
-
self.set_default(default)
|
34
|
-
nsdefault = default
|
35
|
-
end
|
36
|
-
return nsdefault
|
37
|
-
end
|
38
|
-
|
39
|
-
def set_default val
|
40
|
-
NSUserDefaults.standardUserDefaults.setObject(val, forKey:self)
|
41
|
-
end
|
42
|
-
|
43
|
-
def remove_default
|
44
|
-
NSUserDefaults.standardUserDefaults.removeObjectForKey(self)
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|