sugarcube 1.0.7 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/app/app_delegate.rb +0 -1
- data/lib/sugarcube-color/uicolor.rb +0 -14
- data/lib/sugarcube-nsdata/uiimage.rb +8 -3
- data/lib/sugarcube-nsdate/date_parser.rb +30 -7
- data/lib/sugarcube-repl/object.rb +1 -1
- data/lib/sugarcube/version.rb +1 -1
- data/spec/color_other_representations_spec.rb +2 -1
- data/spec/date_parser_spec.rb +50 -1
- data/spec/nsdata_spec.rb +29 -1
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/app/app_delegate.rb
CHANGED
@@ -153,20 +153,6 @@ class UIColor
|
|
153
153
|
break
|
154
154
|
end
|
155
155
|
end
|
156
|
-
Symbol.uicolors__deprecated.each do |old_name, new_name|
|
157
|
-
method = Symbol.uicolors[new_name]
|
158
|
-
if UIColor.send(method) == without_alpha
|
159
|
-
message = "The symbol #{old_name.inspect} has been deprecated in favor of #{new_name.inspect}"
|
160
|
-
if defined?(SugarCube::Legacy)
|
161
|
-
SugarCube::Legacy.log(message)
|
162
|
-
else
|
163
|
-
NSLog(message)
|
164
|
-
end
|
165
|
-
|
166
|
-
system_color = method
|
167
|
-
break
|
168
|
-
end
|
169
|
-
end
|
170
156
|
return system_color
|
171
157
|
end
|
172
158
|
|
@@ -1,8 +1,13 @@
|
|
1
1
|
class UIImage
|
2
2
|
|
3
|
-
# @return [NSData] an NSData object in PNG format
|
4
|
-
def nsdata
|
5
|
-
|
3
|
+
# @return [NSData] an NSData object in PNG or JPG format
|
4
|
+
def nsdata(format=:png, compression=0.9)
|
5
|
+
case format
|
6
|
+
when :png, :PNG
|
7
|
+
UIImagePNGRepresentation(self)
|
8
|
+
when :jpg, :JPG
|
9
|
+
UIImageJPEGRepresentation(self, compression)
|
10
|
+
end
|
6
11
|
end
|
7
12
|
|
8
13
|
end
|
@@ -6,7 +6,12 @@ module SugarCube
|
|
6
6
|
#
|
7
7
|
# => 2013-02-20 09:00:00 -0800
|
8
8
|
def self.parse_date(date_string)
|
9
|
-
|
9
|
+
result = sugarcube_detect(date_string).first
|
10
|
+
if result
|
11
|
+
return result.date
|
12
|
+
else
|
13
|
+
return sugarcube_iso8601(date_string)
|
14
|
+
end
|
10
15
|
end
|
11
16
|
|
12
17
|
# Parse time zone from date
|
@@ -16,7 +21,8 @@ module SugarCube
|
|
16
21
|
# Caveat: This is implemented per Apple documentation. I've never really
|
17
22
|
# seen it work.
|
18
23
|
def self.parse_time_zone(date_string)
|
19
|
-
|
24
|
+
result = sugarcube_detect(date_string).first
|
25
|
+
result && result.timeZone
|
20
26
|
end
|
21
27
|
|
22
28
|
# Parse a date string: E.g.:
|
@@ -27,19 +33,36 @@ module SugarCube
|
|
27
33
|
#
|
28
34
|
# Divide by 3600.0 to get number of hours duration.
|
29
35
|
def self.parse_duration(date_string)
|
30
|
-
|
36
|
+
result = sugarcube_detect(date_string).first
|
37
|
+
result && result.send(:duration)
|
31
38
|
end
|
32
39
|
|
33
40
|
# Parse a date into a raw match array for further processing
|
34
41
|
def self.match(date_string)
|
35
|
-
|
42
|
+
sugarcube_detect(date_string)
|
36
43
|
end
|
37
44
|
|
38
45
|
private
|
39
|
-
def self.
|
40
|
-
@@
|
41
|
-
|
46
|
+
def self.sugarcube_detect(date_string)
|
47
|
+
@@sugarcube_detector ||= NSDataDetector.dataDetectorWithTypes(NSTextCheckingTypeDate, error:Pointer.new(:object))
|
48
|
+
return @@sugarcube_detector.matchesInString(date_string, options:0, range:NSMakeRange(0, date_string.length))
|
42
49
|
end
|
50
|
+
|
51
|
+
def self.sugarcube_iso8601(date_string)
|
52
|
+
@@sugarcube_iso_detectors ||= [
|
53
|
+
"yyyy-MM-dd'T'HH:mm:ss",
|
54
|
+
"yyyy-MM-dd'T'HH:mm:ssZ",
|
55
|
+
"yyyy-MM-dd'T'HH:mm:ss.S",
|
56
|
+
"yyyy-MM-dd'T'HH:mm:ss.SZ",
|
57
|
+
].map do |date_format|
|
58
|
+
formatter = NSDateFormatter.alloc.init
|
59
|
+
formatter.timeZone = NSTimeZone.timeZoneWithAbbreviation "UTC"
|
60
|
+
formatter.dateFormat = date_format
|
61
|
+
formatter
|
62
|
+
end
|
63
|
+
return @@sugarcube_iso_detectors.inject(nil) { |date, formatter| date || formatter.dateFromString(date_string) }
|
64
|
+
end
|
65
|
+
|
43
66
|
end
|
44
67
|
end
|
45
68
|
|
data/lib/sugarcube/version.rb
CHANGED
@@ -18,6 +18,7 @@ describe 'UIColor (CSS)' do
|
|
18
18
|
it "should have a #system_name method" do
|
19
19
|
UIColor.whiteColor.system_name.should == :whiteColor
|
20
20
|
UIColor.blackColor.system_name.should == :blackColor
|
21
|
+
UIColor.lightGrayColor.system_name.should == :lightGrayColor
|
21
22
|
end
|
22
23
|
|
23
24
|
it "should return css color names" do
|
@@ -27,7 +28,7 @@ describe 'UIColor (CSS)' do
|
|
27
28
|
fuchsia: :magenta,
|
28
29
|
}
|
29
30
|
Symbol.css_colors.each do |name, val|
|
30
|
-
name = corrections
|
31
|
+
name = corrections.fetch(name, name)
|
31
32
|
|
32
33
|
color = val.uicolor
|
33
34
|
color.css_name.should == name
|
data/spec/date_parser_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
describe "Base Methods" do
|
2
|
+
|
2
3
|
it "parses a relative natural language string, returning a date" do
|
3
4
|
today = Time.now
|
4
5
|
t = SugarCube::DateParser.parse_date("tomorrow at 7:30 PM")
|
@@ -8,7 +9,7 @@ describe "Base Methods" do
|
|
8
9
|
t.sec.should == 0
|
9
10
|
(t.day - today.day).should == 1
|
10
11
|
end
|
11
|
-
|
12
|
+
|
12
13
|
it "parses a specific natural language string, returning a date" do
|
13
14
|
t = SugarCube::DateParser.parse_date("6/18/13 at 7:30 AM")
|
14
15
|
t.month.should == 6
|
@@ -17,6 +18,54 @@ describe "Base Methods" do
|
|
17
18
|
t.hour.should == 7
|
18
19
|
t.min.should == 30
|
19
20
|
end
|
21
|
+
|
22
|
+
it "returns nil on failure" do
|
23
|
+
t = SugarCube::DateParser.parse_date("NOT A DATE")
|
24
|
+
t.should == nil
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "parses iso8601 dates" do
|
28
|
+
|
29
|
+
it "parses '2013-08-22T21:34:48.874Z'" do
|
30
|
+
t = SugarCube::DateParser.parse_date("2013-08-22T21:34:48.874Z")
|
31
|
+
t.month.should == 8
|
32
|
+
t.day.should == 22
|
33
|
+
t.year.should == 2013
|
34
|
+
t.min.should == 34
|
35
|
+
t.sec.should == 48
|
36
|
+
t.usec.should == 874000
|
37
|
+
end
|
38
|
+
|
39
|
+
it "parses '2013-08-22T21:34:48.874'" do
|
40
|
+
t = SugarCube::DateParser.parse_date("2013-08-22T21:34:48.874")
|
41
|
+
t.month.should == 8
|
42
|
+
t.day.should == 22
|
43
|
+
t.year.should == 2013
|
44
|
+
t.min.should == 34
|
45
|
+
t.sec.should == 48
|
46
|
+
t.usec.should == 874000
|
47
|
+
end
|
48
|
+
|
49
|
+
it "parses '2013-08-22T21:34:48Z'" do
|
50
|
+
t = SugarCube::DateParser.parse_date("2013-08-22T21:34:48Z")
|
51
|
+
t.month.should == 8
|
52
|
+
t.day.should == 22
|
53
|
+
t.year.should == 2013
|
54
|
+
t.min.should == 34
|
55
|
+
t.sec.floor.should == 48
|
56
|
+
end
|
57
|
+
|
58
|
+
it "parses '2013-08-22T21:34:48'" do
|
59
|
+
t = SugarCube::DateParser.parse_date("2013-08-22T21:34:48")
|
60
|
+
t.month.should == 8
|
61
|
+
t.day.should == 22
|
62
|
+
t.year.should == 2013
|
63
|
+
t.min.should == 34
|
64
|
+
t.sec.floor.should == 48
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
20
69
|
end
|
21
70
|
|
22
71
|
describe "String Extensions" do
|
data/spec/nsdata_spec.rb
CHANGED
@@ -27,6 +27,34 @@ describe "NSData" do
|
|
27
27
|
"\u00ab\u03c4\u03b1\u0411\u042c\u2113\u03c3\u00bb".nsdata.nsstring.should == "\u00ab\u03c4\u03b1\u0411\u042c\u2113\u03c3\u00bb"
|
28
28
|
end
|
29
29
|
|
30
|
+
describe "should be able to create an image" do
|
31
|
+
before do
|
32
|
+
@image = 'little_square'.uiimage
|
33
|
+
end
|
34
|
+
|
35
|
+
it "shouldn't need a format" do
|
36
|
+
new_image = @image.nsdata.uiimage
|
37
|
+
new_image.should.is_a? UIImage
|
38
|
+
new_image.size.width.should == @image.size.width * @image.scale
|
39
|
+
new_image.size.height.should == @image.size.height * @image.scale
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should support :png" do
|
43
|
+
new_image = @image.nsdata(:png).uiimage
|
44
|
+
new_image.should.is_a? UIImage
|
45
|
+
new_image.size.width.should == @image.size.width * @image.scale
|
46
|
+
new_image.size.height.should == @image.size.height * @image.scale
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should support :jpg" do
|
50
|
+
new_image = @image.nsdata(:jpg).uiimage
|
51
|
+
new_image.should.is_a? UIImage
|
52
|
+
new_image.size.width.should == @image.size.width * @image.scale
|
53
|
+
new_image.size.height.should == @image.size.height * @image.scale
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
30
58
|
describe "write_to" do
|
31
59
|
|
32
60
|
after do
|
@@ -49,7 +77,7 @@ describe "NSData" do
|
|
49
77
|
path.exists?.should == true
|
50
78
|
url.nsdata.nsstring.should == contents
|
51
79
|
end
|
52
|
-
|
80
|
+
|
53
81
|
end
|
54
82
|
|
55
83
|
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: 1.0
|
4
|
+
version: 1.1.0
|
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: 2013-08-
|
15
|
+
date: 2013-08-23 00:00:00.000000000 Z
|
16
16
|
dependencies: []
|
17
17
|
description: ! '== Description
|
18
18
|
|