numbers_in_words 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +12 -0
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/.rubocop.yml +1171 -0
- data/.travis.yml +7 -0
- data/Gemfile +1 -0
- data/README.md +34 -47
- data/bin/spec +2 -0
- data/lib/numbers_in_words.rb +9 -0
- data/lib/numbers_in_words/duck_punch.rb +2 -2
- data/lib/numbers_in_words/english/language_writer_english.rb +10 -8
- data/lib/numbers_in_words/number_parser.rb +1 -1
- data/lib/numbers_in_words/version.rb +1 -1
- data/numbers_in_words.gemspec +1 -2
- data/spec/language_writer_spec.rb +6 -6
- data/spec/non_monkey_patch_spec.rb +26 -0
- data/spec/number_group_spec.rb +7 -7
- data/spec/numbers_in_words_spec.rb +65 -38
- data/spec/spec_helper.rb +4 -0
- data/spec/words_in_numbers_spec.rb +72 -71
- metadata +29 -50
- data/Gemfile.lock +0 -39
data/spec/spec_helper.rb
CHANGED
@@ -2,105 +2,105 @@ require './spec/spec_helper'
|
|
2
2
|
|
3
3
|
describe WordsInNumbers do
|
4
4
|
it "should do the digits 0-10" do
|
5
|
-
"zero" .in_numbers.
|
6
|
-
"one" .in_numbers.
|
7
|
-
"two" .in_numbers.
|
8
|
-
"three" .in_numbers.
|
9
|
-
"four" .in_numbers.
|
10
|
-
"five" .in_numbers.
|
11
|
-
"six" .in_numbers.
|
12
|
-
"seven" .in_numbers.
|
13
|
-
"eight" .in_numbers.
|
14
|
-
"nine" .in_numbers.
|
5
|
+
expect("zero" .in_numbers).to eq(0)
|
6
|
+
expect("one" .in_numbers).to eq(1)
|
7
|
+
expect("two" .in_numbers).to eq(2)
|
8
|
+
expect("three" .in_numbers).to eq(3)
|
9
|
+
expect("four" .in_numbers).to eq(4)
|
10
|
+
expect("five" .in_numbers).to eq(5)
|
11
|
+
expect("six" .in_numbers).to eq(6)
|
12
|
+
expect("seven" .in_numbers).to eq(7)
|
13
|
+
expect("eight" .in_numbers).to eq(8)
|
14
|
+
expect("nine" .in_numbers).to eq(9)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should handle numbers for which there is one word" do
|
18
|
-
"ten" .in_numbers.
|
19
|
-
"eleven" .in_numbers.
|
20
|
-
"twelve" .in_numbers.
|
21
|
-
"thirteen" .in_numbers.
|
22
|
-
"fourteen" .in_numbers.
|
23
|
-
"fifteen" .in_numbers.
|
24
|
-
"sixteen" .in_numbers.
|
25
|
-
"seventeen" .in_numbers.
|
26
|
-
"eighteen" .in_numbers.
|
27
|
-
"nineteen" .in_numbers.
|
28
|
-
"twenty" .in_numbers.
|
18
|
+
expect("ten" .in_numbers).to eq(10)
|
19
|
+
expect("eleven" .in_numbers).to eq(11)
|
20
|
+
expect("twelve" .in_numbers).to eq(12)
|
21
|
+
expect("thirteen" .in_numbers).to eq(13)
|
22
|
+
expect("fourteen" .in_numbers).to eq(14)
|
23
|
+
expect("fifteen" .in_numbers).to eq(15)
|
24
|
+
expect("sixteen" .in_numbers).to eq(16)
|
25
|
+
expect("seventeen" .in_numbers).to eq(17)
|
26
|
+
expect("eighteen" .in_numbers).to eq(18)
|
27
|
+
expect("nineteen" .in_numbers).to eq(19)
|
28
|
+
expect("twenty" .in_numbers).to eq(20)
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should handle two word numbers up to 100" do
|
32
|
-
"twenty one" .in_numbers.
|
33
|
-
"twenty two" .in_numbers.
|
34
|
-
"twenty three" .in_numbers.
|
35
|
-
"twenty four" .in_numbers.
|
36
|
-
"twenty five" .in_numbers.
|
37
|
-
"twenty six" .in_numbers.
|
38
|
-
"twenty seven" .in_numbers.
|
39
|
-
"twenty eight" .in_numbers.
|
40
|
-
"seventy six" .in_numbers.
|
41
|
-
"ninety nine" .in_numbers.
|
32
|
+
expect("twenty one" .in_numbers).to eq(21)
|
33
|
+
expect("twenty two" .in_numbers).to eq(22)
|
34
|
+
expect("twenty three" .in_numbers).to eq(23)
|
35
|
+
expect("twenty four" .in_numbers).to eq(24)
|
36
|
+
expect("twenty five" .in_numbers).to eq(25)
|
37
|
+
expect("twenty six" .in_numbers).to eq(26)
|
38
|
+
expect("twenty seven" .in_numbers).to eq(27)
|
39
|
+
expect("twenty eight" .in_numbers).to eq(28)
|
40
|
+
expect("seventy six" .in_numbers).to eq(76)
|
41
|
+
expect("ninety nine" .in_numbers).to eq(99)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should handle hundreds" do
|
45
|
-
"one hundred" .in_numbers.
|
46
|
-
"two hundred" .in_numbers.
|
47
|
-
"three hundred" .in_numbers.
|
48
|
-
"nine hundred" .in_numbers.
|
49
|
-
"one hundred and seventy six" .in_numbers.
|
50
|
-
"one hundred and seventy nine" .in_numbers.
|
51
|
-
"nine hundred and ninety nine" .in_numbers.
|
45
|
+
expect("one hundred" .in_numbers).to eq(100)
|
46
|
+
expect("two hundred" .in_numbers).to eq(200)
|
47
|
+
expect("three hundred" .in_numbers).to eq(300)
|
48
|
+
expect("nine hundred" .in_numbers).to eq(900)
|
49
|
+
expect("one hundred and seventy six" .in_numbers).to eq(176)
|
50
|
+
expect("one hundred and seventy nine" .in_numbers).to eq(179)
|
51
|
+
expect("nine hundred and ninety nine" .in_numbers).to eq(999)
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should handle unusual hundreds" do
|
55
|
-
"eleven hundred" .in_numbers.
|
56
|
-
"twelve hundred" .in_numbers.
|
57
|
-
"thirteen hundred" .in_numbers.
|
58
|
-
"fifteen hundred" .in_numbers.
|
59
|
-
"nineteen hundred" .in_numbers.
|
55
|
+
expect("eleven hundred" .in_numbers).to eq(1100)
|
56
|
+
expect("twelve hundred" .in_numbers).to eq(1200)
|
57
|
+
expect("thirteen hundred" .in_numbers).to eq(1300)
|
58
|
+
expect("fifteen hundred" .in_numbers).to eq(1500)
|
59
|
+
expect("nineteen hundred" .in_numbers).to eq(1900)
|
60
60
|
|
61
61
|
end
|
62
62
|
it "should handle thousands" do
|
63
|
-
"two thousand and one" .in_numbers .
|
64
|
-
"one thousand" .in_numbers .
|
65
|
-
"two thousand" .in_numbers .
|
66
|
-
"three thousand" .in_numbers .
|
67
|
-
"nine thousand" .in_numbers .
|
68
|
-
"nine thousand two hundred" .in_numbers .
|
69
|
-
"nine thousand two hundred and seven" .in_numbers .
|
70
|
-
"nine thousand two hundred and ninety seven" .in_numbers .
|
63
|
+
expect("two thousand and one" .in_numbers) .to eq(2001)
|
64
|
+
expect("one thousand" .in_numbers) .to eq(1000)
|
65
|
+
expect("two thousand" .in_numbers) .to eq(2000)
|
66
|
+
expect("three thousand" .in_numbers) .to eq(3000)
|
67
|
+
expect("nine thousand" .in_numbers) .to eq(9000)
|
68
|
+
expect("nine thousand two hundred" .in_numbers) .to eq(9200)
|
69
|
+
expect("nine thousand two hundred and seven" .in_numbers) .to eq(9207)
|
70
|
+
expect("nine thousand two hundred and ninety seven" .in_numbers) .to eq(9297)
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should handle larger numbers" do
|
74
|
-
"one million" .in_numbers .
|
75
|
-
"two googol five billion and seventy six" .in_numbers .
|
76
|
-
"thirty seven million" .in_numbers .
|
77
|
-
"twenty six googol" .in_numbers .
|
74
|
+
expect("one million" .in_numbers) .to eq(1000000)
|
75
|
+
expect("two googol five billion and seventy six" .in_numbers) .to eq(2*10**100 + 5*10**9 + 76)
|
76
|
+
expect("thirty seven million" .in_numbers) .to eq(37 * 10**6)
|
77
|
+
expect("twenty six googol" .in_numbers) .to eq(26 * 10**100)
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should handle numbers in hundreds of thousands etc" do
|
81
|
-
"nine hundred thousand" .in_numbers .
|
82
|
-
"three hundred and fifty seven thousand" .in_numbers .
|
83
|
-
"five million three hundred and fifty seven thousand" .in_numbers .
|
84
|
-
"nine hundred and ninety nine trillion" .in_numbers .
|
81
|
+
expect("nine hundred thousand" .in_numbers) .to eq(900000)
|
82
|
+
expect("three hundred and fifty seven thousand" .in_numbers) .to eq(357000)
|
83
|
+
expect("five million three hundred and fifty seven thousand" .in_numbers) .to eq(5357000)
|
84
|
+
expect("nine hundred and ninety nine trillion" .in_numbers) .to eq(999 * 10**12)
|
85
85
|
end
|
86
86
|
it "should handle negative numbers" do
|
87
|
-
"minus one" .in_numbers .
|
88
|
-
"minus two googol" .in_numbers .
|
89
|
-
"minus nine hundred and ninety nine trillion" .in_numbers .
|
87
|
+
expect("minus one" .in_numbers) .to eq(-1)
|
88
|
+
expect("minus two googol" .in_numbers) .to eq(-2 * 10**100)
|
89
|
+
expect("minus nine hundred and ninety nine trillion" .in_numbers) .to eq(-999 * 10**12)
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should ignore punctuation and capitalisation" do
|
93
|
-
"Minus one" .in_numbers .
|
94
|
-
"FIVE Million, three hundred and fifty-seVen Thousand" .in_numbers .
|
95
|
-
"FIVE,,./';';';[] Million, three hundred and fifty-seVen Thousand" .in_numbers .
|
93
|
+
expect("Minus one" .in_numbers) .to eq(-1)
|
94
|
+
expect("FIVE Million, three hundred and fifty-seVen Thousand" .in_numbers) .to eq(5357000)
|
95
|
+
expect("FIVE,,./';';';[] Million, three hundred and fifty-seVen Thousand" .in_numbers) .to eq(5357000)
|
96
96
|
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should handle decimal points" do
|
100
|
-
"one point one" .in_numbers .
|
100
|
+
expect("one point one" .in_numbers) .to eq(1.1)
|
101
101
|
|
102
|
-
"zero point seven six five three four" .in_numbers .
|
103
|
-
"one trillion point six" .in_numbers .
|
102
|
+
expect("zero point seven six five three four" .in_numbers) .to eq(0.76534)
|
103
|
+
expect("one trillion point six" .in_numbers) .to eq(10**12 + 0.6)
|
104
104
|
|
105
105
|
long_number = <<-NUMBER
|
106
106
|
nine duotrigintillion seven hundred and seventy seven untrigintillion
|
@@ -124,11 +124,12 @@ describe WordsInNumbers do
|
|
124
124
|
million ninety three thousand seven hundred and ninety one point
|
125
125
|
eight nine five six four three two one eight nine five six seven eight
|
126
126
|
NUMBER
|
127
|
-
long_number.in_numbers.
|
127
|
+
expect(long_number.in_numbers).to eq(
|
128
128
|
9777059160806736471970632827836952710801948705683106707757426795746813127465237139153046752803093791.89564321895678
|
129
|
+
)
|
129
130
|
|
130
|
-
"seventy five point eight four three two seven six nine four five one eight".
|
131
|
-
in_numbers.
|
131
|
+
expect("seventy five point eight four three two seven six nine four five one eight".
|
132
|
+
in_numbers).to eq(75.84327694518)
|
132
133
|
end
|
133
134
|
|
134
135
|
end
|
metadata
CHANGED
@@ -1,77 +1,61 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numbers_in_words
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.2.0
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Mark Burns
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-11-30 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
type: :runtime
|
16
|
-
version_requirements: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
14
|
name: activesupport
|
23
|
-
prerelease: false
|
24
15
|
requirement: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
16
|
requirements:
|
27
|
-
- -
|
17
|
+
- - ">="
|
28
18
|
- !ruby/object:Gem::Version
|
29
19
|
version: '0'
|
30
|
-
|
31
|
-
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
32
22
|
version_requirements: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
23
|
requirements:
|
35
|
-
- -
|
24
|
+
- - ">="
|
36
25
|
- !ruby/object:Gem::Version
|
37
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
38
28
|
name: rspec
|
39
|
-
prerelease: false
|
40
29
|
requirement: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
30
|
requirements:
|
43
|
-
- -
|
31
|
+
- - "~>"
|
44
32
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
46
|
-
- !ruby/object:Gem::Dependency
|
33
|
+
version: 3.4.0
|
47
34
|
type: :development
|
48
|
-
version_requirements: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ! '>='
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
|
-
name: debugger
|
55
35
|
prerelease: false
|
56
|
-
|
57
|
-
none: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
37
|
requirements:
|
59
|
-
- -
|
38
|
+
- - "~>"
|
60
39
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
-
description:
|
40
|
+
version: 3.4.0
|
41
|
+
description: "#in_words method for integers and #in_numbers for strings"
|
63
42
|
email:
|
64
43
|
- markthedeveloper@gmail.com
|
65
|
-
executables:
|
44
|
+
executables:
|
45
|
+
- spec
|
66
46
|
extensions: []
|
67
47
|
extra_rdoc_files: []
|
68
48
|
files:
|
69
|
-
- .
|
49
|
+
- ".codeclimate.yml"
|
50
|
+
- ".gitignore"
|
51
|
+
- ".rspec"
|
52
|
+
- ".rubocop.yml"
|
53
|
+
- ".travis.yml"
|
70
54
|
- Gemfile
|
71
|
-
- Gemfile.lock
|
72
55
|
- LICENSE.txt
|
73
56
|
- README.md
|
74
57
|
- Rakefile
|
58
|
+
- bin/spec
|
75
59
|
- lib/numbers_in_words.rb
|
76
60
|
- lib/numbers_in_words/duck_punch.rb
|
77
61
|
- lib/numbers_in_words/english/constants.rb
|
@@ -84,43 +68,38 @@ files:
|
|
84
68
|
- lib/numbers_in_words/version.rb
|
85
69
|
- numbers_in_words.gemspec
|
86
70
|
- spec/language_writer_spec.rb
|
71
|
+
- spec/non_monkey_patch_spec.rb
|
87
72
|
- spec/number_group_spec.rb
|
88
73
|
- spec/numbers_in_words_spec.rb
|
89
74
|
- spec/spec_helper.rb
|
90
75
|
- spec/words_in_numbers_spec.rb
|
91
76
|
homepage: http://github.com/markburns/numbers_in_words
|
92
77
|
licenses: []
|
78
|
+
metadata: {}
|
93
79
|
post_install_message:
|
94
80
|
rdoc_options: []
|
95
81
|
require_paths:
|
96
82
|
- lib
|
97
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
-
none: false
|
99
84
|
requirements:
|
100
|
-
- -
|
85
|
+
- - ">="
|
101
86
|
- !ruby/object:Gem::Version
|
102
|
-
segments:
|
103
|
-
- 0
|
104
|
-
hash: -1513551754306869579
|
105
87
|
version: '0'
|
106
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
-
none: false
|
108
89
|
requirements:
|
109
|
-
- -
|
90
|
+
- - ">="
|
110
91
|
- !ruby/object:Gem::Version
|
111
|
-
segments:
|
112
|
-
- 0
|
113
|
-
hash: -1513551754306869579
|
114
92
|
version: '0'
|
115
93
|
requirements: []
|
116
94
|
rubyforge_project:
|
117
|
-
rubygems_version:
|
95
|
+
rubygems_version: 2.4.5
|
118
96
|
signing_key:
|
119
|
-
specification_version:
|
120
|
-
summary:
|
97
|
+
specification_version: 4
|
98
|
+
summary: 'Example: 123.in_words # => "one hundred and twenty three", "seventy-five
|
121
99
|
point eight".in_numbers # = > 75.8'
|
122
100
|
test_files:
|
123
101
|
- spec/language_writer_spec.rb
|
102
|
+
- spec/non_monkey_patch_spec.rb
|
124
103
|
- spec/number_group_spec.rb
|
125
104
|
- spec/numbers_in_words_spec.rb
|
126
105
|
- spec/spec_helper.rb
|
data/Gemfile.lock
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
numbers_in_words (0.2.0)
|
5
|
-
activesupport
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
activesupport (3.2.10)
|
11
|
-
i18n (~> 0.6)
|
12
|
-
multi_json (~> 1.0)
|
13
|
-
columnize (0.3.6)
|
14
|
-
debugger (1.2.3)
|
15
|
-
columnize (>= 0.3.1)
|
16
|
-
debugger-linecache (~> 1.1.1)
|
17
|
-
debugger-ruby_core_source (~> 1.1.5)
|
18
|
-
debugger-linecache (1.1.2)
|
19
|
-
debugger-ruby_core_source (>= 1.1.1)
|
20
|
-
debugger-ruby_core_source (1.1.6)
|
21
|
-
diff-lcs (1.1.3)
|
22
|
-
i18n (0.6.1)
|
23
|
-
multi_json (1.5.0)
|
24
|
-
rspec (2.12.0)
|
25
|
-
rspec-core (~> 2.12.0)
|
26
|
-
rspec-expectations (~> 2.12.0)
|
27
|
-
rspec-mocks (~> 2.12.0)
|
28
|
-
rspec-core (2.12.2)
|
29
|
-
rspec-expectations (2.12.1)
|
30
|
-
diff-lcs (~> 1.1.3)
|
31
|
-
rspec-mocks (2.12.1)
|
32
|
-
|
33
|
-
PLATFORMS
|
34
|
-
ruby
|
35
|
-
|
36
|
-
DEPENDENCIES
|
37
|
-
debugger
|
38
|
-
numbers_in_words!
|
39
|
-
rspec
|