numbertotext-ruby 1.0.0 → 1.0.1
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.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/lib/numbertotext.rb +9 -2
- data/lib/numbertotext/version.rb +1 -1
- data/spec/lib/numbertotext_spec.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68bddb6dae31e1b8595a77c4eb5e30bf5b6bf05d
|
4
|
+
data.tar.gz: 3918d5ba5f1ea103365e9b55e35613790d5ba20b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a9d4a36d28e991e09cc40a2d54aa4cd31b63692ed4bd7619c7b42dfe82a75413d3c4b895a9a0e1c43d4a245a31e5eefe08583a05ddb59470b06d7859c155a7b
|
7
|
+
data.tar.gz: 27a9113f36d6f2c7ef76194486a8921ced5bb820894e536da0239d929a15db9de3f210bde4d6460c449de71284a32ff25d761317681a77855a910a7148d0cdcf
|
data/README.md
CHANGED
@@ -14,6 +14,20 @@ Or install it yourself as:
|
|
14
14
|
|
15
15
|
$ gem install numbertotext-ruby
|
16
16
|
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Require the numbertotext library
|
20
|
+
|
21
|
+
require 'numbertotext'
|
22
|
+
|
23
|
+
Convert a number you want (e.g. 1000)
|
24
|
+
|
25
|
+
NumberToText.convert(1000)
|
26
|
+
|
27
|
+
Alternatively, you could also convert a number by simply calling the "to_text" method on it
|
28
|
+
|
29
|
+
1000.to_text = "one thousand"
|
30
|
+
|
17
31
|
|
18
32
|
## Contributing
|
19
33
|
|
data/lib/numbertotext.rb
CHANGED
@@ -28,7 +28,9 @@ module NumberToText
|
|
28
28
|
|
29
29
|
|
30
30
|
def self.convert(number)
|
31
|
-
if number <
|
31
|
+
if number < 0
|
32
|
+
return 'minus ' + convert(-1*number)
|
33
|
+
elsif number < 20 && number > -1
|
32
34
|
return @dictionary1[number]
|
33
35
|
elsif number < 100 && number > 19
|
34
36
|
convert_20_to_99(number)
|
@@ -44,5 +46,10 @@ module NumberToText
|
|
44
46
|
return 'number too large. please try with a number lower than or equal to 999999999999'
|
45
47
|
end
|
46
48
|
end
|
47
|
-
|
48
49
|
end
|
50
|
+
|
51
|
+
class Fixnum
|
52
|
+
def to_text
|
53
|
+
NumberToText.convert(self)
|
54
|
+
end
|
55
|
+
end
|
data/lib/numbertotext/version.rb
CHANGED
@@ -22,6 +22,12 @@ describe NumberToText do
|
|
22
22
|
expect(actual).to eq(expected)
|
23
23
|
end
|
24
24
|
|
25
|
+
it 'should convert 20' do
|
26
|
+
actual = 20.to_text
|
27
|
+
expected = 'twenty'
|
28
|
+
expect(actual).to eq(expected)
|
29
|
+
end
|
30
|
+
|
25
31
|
it 'should convert 21' do
|
26
32
|
actual = NumberToText.convert(21)
|
27
33
|
expected = 'twenty-one'
|
@@ -149,4 +155,10 @@ describe NumberToText do
|
|
149
155
|
expect(actual).to eq(expected)
|
150
156
|
end
|
151
157
|
|
158
|
+
it 'should convert -1000' do
|
159
|
+
actual = NumberToText.convert(-1000)
|
160
|
+
expected = 'minus one thousand'
|
161
|
+
expect(actual).to eq(expected)
|
162
|
+
end
|
163
|
+
|
152
164
|
end
|