sugarcube 1.5.4 → 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +4 -0
- data/lib/sugarcube-numbers/nsstring.rb +7 -3
- data/lib/sugarcube/version.rb +1 -1
- data/spec/nsstring_spec.rb +36 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5bd88350a86ee4e4bedb8382ae815b7a6f593f3
|
4
|
+
data.tar.gz: bee437d228cd18da4bb87a69ded96ac42ae5c7fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08fc26e8d84dfd3a5b83f27f1da1f3fc349eb93b822efe693615164afe2e65c16c27402a1bc53f716db4d3dc153648e79ec088b8005358eeeaf82751b95d4fee
|
7
|
+
data.tar.gz: 54b8fc6295e7bc12375a98e13291506bd6f368ef8e1964beacbfa6e91f9b0154f5b5bc1bb852a203492a3659da54b47c2b740a115f64120e4b4f1dde7269b6ff
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -984,6 +984,10 @@ if input.nan?
|
|
984
984
|
UIAlertView.alert('not a number!')
|
985
985
|
else
|
986
986
|
number = input.to_number
|
987
|
+
# convert a currency
|
988
|
+
number = input.to_number(NSNumberFormatterCurrencyStyle)
|
989
|
+
# convert from symbol, requires 'sugarcube-constants'
|
990
|
+
number = input.to_number(:currency)
|
987
991
|
end
|
988
992
|
```
|
989
993
|
|
@@ -1,12 +1,16 @@
|
|
1
1
|
class NSString
|
2
2
|
|
3
3
|
# @return boolean
|
4
|
-
def nan?
|
5
|
-
self.to_number.nil?
|
4
|
+
def nan?(style=NSNumberFormatterDecimalStyle)
|
5
|
+
self.to_number(style).nil?
|
6
6
|
end
|
7
7
|
|
8
|
-
def to_number
|
8
|
+
def to_number(style=NSNumberFormatterDecimalStyle)
|
9
|
+
if style.respond_to?(:nsnumberstyle)
|
10
|
+
style = style.nsnumberstyle
|
11
|
+
end
|
9
12
|
number_formatter = NSNumberFormatter.new
|
13
|
+
number_formatter.numberStyle = style
|
10
14
|
number_formatter.numberFromString(self)
|
11
15
|
end
|
12
16
|
|
data/lib/sugarcube/version.rb
CHANGED
data/spec/nsstring_spec.rb
CHANGED
@@ -93,9 +93,42 @@ describe "NSString" do
|
|
93
93
|
'hello'._.should == 'howdy'
|
94
94
|
end
|
95
95
|
|
96
|
-
|
97
|
-
|
98
|
-
|
96
|
+
describe "should have a #nan? method" do
|
97
|
+
it 'should return true for non-numbers' do
|
98
|
+
"pi".nan?.should.equal true
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should return false for numbers' do
|
102
|
+
"3.12159".nan?.should.equal false
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should not detect currencies' do
|
106
|
+
"$3.12159".nan?.should.equal true
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should return false for valid currencies' do
|
110
|
+
"$3.12159".nan?(:currency).should.equal false
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "should have a #to_number method" do
|
115
|
+
it 'should detect simple integers' do
|
116
|
+
'123'.to_number.should == 123
|
117
|
+
'1,000'.to_number.should == 1000
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should detect simple floats' do
|
121
|
+
'1.25'.to_number.should == 1.25
|
122
|
+
'1,000.25'.to_number.should == 1000.25
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should return nil for non-numbers' do
|
126
|
+
'pi'.to_number.should == nil
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should parse currencies' do
|
130
|
+
'$123.25'.to_number(:currency).should == 123.25
|
131
|
+
end
|
99
132
|
end
|
100
133
|
|
101
134
|
it "should have a #remove_accents method" do
|
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.5.
|
4
|
+
version: 1.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin T.A. Gray
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-03-
|
14
|
+
date: 2014-03-18 00:00:00.000000000 Z
|
15
15
|
dependencies: []
|
16
16
|
description: |
|
17
17
|
== Description
|