numerizer 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzQwYWJkNDgwYTNiODg0NDYxNWUzM2NhYjY0OTMyOWE1MTEzYzQ2Yg==
5
+ data.tar.gz: !binary |-
6
+ NDIxMmMwMzZlOGRiOTM4MTg1MmRhOGMwZmRjYmM4NGViYTgyNjkxOQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ Zjk2OTAyYzE0Y2I2NGIzNTIzNzkwYTVlMmQ3OGI0Nzc4M2JjMmNkYTU5YjE3
10
+ ZmZjMWNhN2NlNTQzYzcyYzI4NDMxZmQxYTdlNDk3ODcwNjIxZGQ4NWU2OTVi
11
+ NmJkYTA2YTBhYTBiNGY1Yzc4NDIyMjE2Y2Q4ZGM1OGM3NzQ4NDI=
12
+ data.tar.gz: !binary |-
13
+ ZWM5YWYwNDI5MTFjZWNiZTkxZmZmZmYyYTM5MzYxZTc1ZjFlYzg2YWE0MGE0
14
+ MWFmN2MyYjU3ZWMyMzhkOTM1YzM2MzQwNmMxOTNlOWUxNjQ4ZmRkYWQ3Nzcx
15
+ YzFiMzYwYmY5MzQzMzUwNThlYzk0OTFkYzE3YjU5ZGFkMmQ3ODg=
data/Rakefile CHANGED
@@ -9,6 +9,7 @@ begin
9
9
  gem.description = "Numerizer is a gem to help with parsing numbers in natural language from strings (ex forty two). It was extracted from the awesome Chronic gem http://github.com/evaryont/chronic."
10
10
  gem.email = "duff.john@gmail.com"
11
11
  gem.homepage = "http://github.com/jduff/numerizer"
12
+ gem.license = 'MIT'
12
13
  gem.authors = ["John Duff"]
13
14
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
15
  end
@@ -18,10 +19,9 @@ rescue LoadError
18
19
  end
19
20
 
20
21
  require 'rake/testtask'
21
- Rake::TestTask.new(:test) do |test|
22
- test.libs << 'lib' << 'test'
23
- test.pattern = 'test/**/test_*.rb'
24
- test.verbose = true
22
+ Rake::TestTask.new(:test) do |t|
23
+ t.libs << 'test'
24
+ t.test_files = Dir['test/test_*.rb']
25
25
  end
26
26
 
27
27
  begin
@@ -37,20 +37,20 @@ rescue LoadError
37
37
  end
38
38
  end
39
39
 
40
- task :test => :check_dependencies
40
+ # task :test => :check_dependencies
41
41
 
42
42
  task :default => :test
43
43
 
44
- require 'rake/rdoctask'
45
- Rake::RDocTask.new do |rdoc|
46
- if File.exist?('VERSION')
47
- version = File.read('VERSION')
48
- else
49
- version = ""
50
- end
44
+ # require 'rake/rdoctask'
45
+ # Rake::RDocTask.new do |rdoc|
46
+ # if File.exist?('VERSION')
47
+ # version = File.read('VERSION')
48
+ # else
49
+ # version = ""
50
+ # end
51
51
 
52
- rdoc.rdoc_dir = 'rdoc'
53
- rdoc.title = "numerizer #{version}"
54
- rdoc.rdoc_files.include('README*')
55
- rdoc.rdoc_files.include('lib/**/*.rb')
56
- end
52
+ # rdoc.rdoc_dir = 'rdoc'
53
+ # rdoc.title = "numerizer #{version}"
54
+ # rdoc.rdoc_files.include('README*')
55
+ # rdoc.rdoc_files.include('lib/**/*.rb')
56
+ # end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -1,133 +1,168 @@
1
1
  # LICENSE:
2
- #
2
+ #
3
3
  # (The MIT License)
4
- #
4
+ #
5
5
  # Copyright © 2008 Tom Preston-Werner
6
- #
6
+ #
7
7
  # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
- #
8
+ #
9
9
  # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
- #
10
+ #
11
11
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
12
 
13
13
  require 'strscan'
14
14
 
15
15
  class Numerizer
16
16
 
17
- DIRECT_NUMS = [
18
- ['eleven', '11'],
19
- ['twelve', '12'],
20
- ['thirteen', '13'],
21
- ['fourteen', '14'],
22
- ['fifteen', '15'],
23
- ['sixteen', '16'],
24
- ['seventeen', '17'],
25
- ['eighteen', '18'],
26
- ['nineteen', '19'],
27
- ['ninteen', '19'], # Common mis-spelling
28
- ['zero', '0'],
29
- ['ten', '10'],
30
- ['\ba[\b^$]', '1'] # doesn't make sense for an 'a' at the end to be a 1
31
- ]
32
-
33
- SINGLE_NUMS = [
34
- ['one', 1],
35
- ['two', 2],
36
- ['three', 3],
37
- #['four(\W|$)', '4\1'], # The weird regex is so that it matches four but not fourty
38
- ['four', 4],
39
- ['five', 5],
40
- ['six', 6],
41
- ['seven', 7],
42
- ['eight', 8],
43
- ['nine', 9]
44
- ]
45
-
46
- TEN_PREFIXES = [ ['twenty', 20],
47
- ['thirty', 30],
48
- ['forty', 40],
49
- ['fourty', 40], # Common misspelling
50
- ['fifty', 50],
51
- ['sixty', 60],
52
- ['seventy', 70],
53
- ['eighty', 80],
54
- ['ninety', 90]
55
- ]
56
-
57
- BIG_PREFIXES = [ ['hundred', 100],
58
- ['thousand', 1000],
59
- ['million', 1_000_000],
60
- ['billion', 1_000_000_000],
61
- ['trillion', 1_000_000_000_000],
62
- ]
63
-
64
- FRACTIONS = [ ['half', 2],
65
- ['third(s)?', 3],
66
- ['fourth(s)?', 4],
67
- ['quarter(s)?', 4],
68
- ['fifth(s)?', 5],
69
- ['sixth(s)?', 6],
70
- ['seventh(s)?', 7],
71
- ['eighth(s)?', 8],
72
- ['nineth(s)?', 9],
73
- ]
74
-
75
- def self.numerize(string)
76
- string = string.dup
77
-
78
- # preprocess
79
- string.gsub!(/ +|([^\d])-([^\d])/, '\1 \2') # will mutilate hyphenated-words
80
-
81
- # easy/direct replacements
82
-
83
- (DIRECT_NUMS + SINGLE_NUMS).each do |dn|
84
- # string.gsub!(/#{dn[0]}/i, '<num>' + dn[1])
85
- string.gsub!(/(^|\W+)#{dn[0]}($|\W+)/i) {"#{$1}<num>" + dn[1].to_s + $2}
86
- end
87
-
88
- # ten, twenty, etc.
89
- # TEN_PREFIXES.each do |tp|
90
- # string.gsub!(/(?:#{tp[0]}) *<num>(\d(?=[^\d]|$))*/i) {'<num>' + (tp[1] + $1.to_i).to_s}
91
- # end
92
- TEN_PREFIXES.each do |tp|
93
- SINGLE_NUMS.each do |dn|
94
- string.gsub!(/(^|\W+)#{tp[0]}#{dn[0]}($|\W+)/i) {
95
- "#{$1}<num>" + (tp[1] + dn[1]).to_s + $2
96
- }
97
- end
98
- string.gsub!(/(^|\W+)#{tp[0]}($|\W+)/i) { "#{$1}<num>" + tp[1].to_s + $2 }
99
- end
100
-
101
- # handle fractions
102
- FRACTIONS.each do |tp|
103
- string.gsub!(/a #{tp[0]}/i) { '<num>1/' + tp[1].to_s }
104
- string.gsub!(/\s#{tp[0]}/i) { '/' + tp[1].to_s }
105
- end
106
-
107
- # evaluate fractions when preceded by another number
17
+ DIRECT_NUMS = [
18
+ ['eleven', '11'],
19
+ ['twelve', '12'],
20
+ ['thirteen', '13'],
21
+ ['fourteen', '14'],
22
+ ['fifteen', '15'],
23
+ ['sixteen', '16'],
24
+ ['seventeen', '17'],
25
+ ['eighteen', '18'],
26
+ ['nineteen', '19'],
27
+ ['ninteen', '19'], # Common mis-spelling
28
+ ['zero', '0'],
29
+ ['ten', '10'],
30
+ ['\ba[\b^$]', '1'] # doesn't make sense for an 'a' at the end to be a 1
31
+ ]
32
+
33
+ SINGLE_NUMS = [
34
+ ['one', 1],
35
+ ['two', 2],
36
+ ['three', 3],
37
+ ['four', 4],
38
+ ['five', 5],
39
+ ['six', 6],
40
+ ['seven', 7],
41
+ ['eight', 8],
42
+ ['nine', 9]
43
+ ]
44
+
45
+ TEN_PREFIXES = [
46
+ ['twenty', 20],
47
+ ['thirty', 30],
48
+ ['forty', 40],
49
+ ['fourty', 40], # Common misspelling
50
+ ['fifty', 50],
51
+ ['sixty', 60],
52
+ ['seventy', 70],
53
+ ['eighty', 80],
54
+ ['ninety', 90]
55
+ ]
56
+
57
+ BIG_PREFIXES = [
58
+ ['hundred', 100],
59
+ ['thousand', 1000],
60
+ ['million', 1_000_000],
61
+ ['billion', 1_000_000_000],
62
+ ['trillion', 1_000_000_000_000],
63
+ ]
64
+
65
+ FRACTIONS = [
66
+ ['half', 2],
67
+ ['third(s)?', 3],
68
+ ['fourth(s)?', 4],
69
+ ['quarter(s)?', 4],
70
+ ['fifth(s)?', 5],
71
+ ['sixth(s)?', 6],
72
+ ['seventh(s)?', 7],
73
+ ['eighth(s)?', 8],
74
+ ['nineth(s)?', 9],
75
+ ]
76
+
77
+ SINGLE_ORDINALS = [
78
+ ['first', 1],
79
+ ['third', 3],
80
+ ['fourth', 4],
81
+ ['fifth', 5],
82
+ ['sixth', 6],
83
+ ['seventh', 7],
84
+ ['eighth', 8],
85
+ ['ninth', 9]
86
+ ]
87
+
88
+ DIRECT_ORDINALS = [
89
+ ['tenth', '10'],
90
+ ['eleventh', '11'],
91
+ ['twelfth', '12'],
92
+ ['thirteenth', '13'],
93
+ ['fourteenth', '14'],
94
+ ['fifteenth', '15'],
95
+ ['sixteenth', '16'],
96
+ ['seventeenth', '17'],
97
+ ['eighteenth', '18'],
98
+ ['nineteenth', '19'],
99
+ ['twentieth', '20'],
100
+ ['thirtieth', '30'],
101
+ ['fourtieth', '40'],
102
+ ['fiftieth', '50'],
103
+ ['sixtieth', '60'],
104
+ ['seventieth', '70'],
105
+ ['eightieth', '80'],
106
+ ['ninetieth', '90']
107
+ ]
108
+
109
+ def self.numerize(string)
110
+ string = string.dup
111
+
112
+ # preprocess
113
+ string.gsub!(/ +|([^\d])-([^\d])/, '\1 \2') # will mutilate hyphenated-words
114
+
115
+ # easy/direct replacements
116
+ (DIRECT_NUMS + SINGLE_NUMS).each do |dn|
117
+ string.gsub!(/(^|\W)#{dn[0]}(?=$|\W)/i, '\1<num>' + dn[1].to_s)
118
+ end
119
+
120
+ # ten, twenty, etc.
121
+ TEN_PREFIXES.each do |tp|
122
+ SINGLE_NUMS.each do |dn|
123
+ string.gsub!(/(^|\W)#{tp[0]}#{dn[0]}(?=$|\W)/i, '\1<num>' + (tp[1] + dn[1]).to_s)
124
+ end
125
+ SINGLE_ORDINALS.each do |dn|
126
+ string.gsub!(/(^|\W)#{tp[0]}(\s)?#{dn[0]}(?=$|\W)/i, '\1<num>' + (tp[1] + dn[1]).to_s + dn[0][-2, 2])
127
+ end
128
+ string.gsub!(/(^|\W)#{tp[0]}(?=$|\W)/i, '\1<num>' + tp[1].to_s)
129
+ end
130
+
131
+ # handle fractions
132
+ FRACTIONS.each do |tp|
133
+ string.gsub!(/a #{tp[0]}(?=$|\W)/i, '<num>1/' + tp[1].to_s)
134
+ string.gsub!(/\s#{tp[0]}(?=$|\W)/i, '/' + tp[1].to_s)
135
+ end
136
+
137
+ (DIRECT_ORDINALS + SINGLE_ORDINALS).each do |on|
138
+ string.gsub!(/(^|\W)#{on[0]}(?=$|\W)/i, '\1<num>' + on[1].to_s + on[0][-2, 2])
139
+ end
140
+
141
+ # evaluate fractions when preceded by another number
108
142
  string.gsub!(/(\d+)(?: | and |-)+(<num>|\s)*(\d+)\s*\/\s*(\d+)/i) { ($1.to_f + ($3.to_f/$4.to_f)).to_s }
109
-
110
- # hundreds, thousands, millions, etc.
111
- BIG_PREFIXES.each do |bp|
112
- string.gsub!(/(?:<num>)?(\d*) *#{bp[0]}/i) { '<num>' + (bp[1] * $1.to_i).to_s}
113
- andition(string)
114
- end
115
143
 
116
- andition(string)
144
+ # hundreds, thousands, millions, etc.
145
+ BIG_PREFIXES.each do |bp|
146
+ string.gsub!(/(?:<num>)?(\d*) *#{bp[0]}/i) { $1.empty? ? bp[1] : '<num>' + (bp[1] * $1.to_i).to_s }
147
+ andition(string)
148
+ end
117
149
 
118
- string.gsub(/<num>/, '')
119
- end
150
+ andition(string)
120
151
 
121
- private
152
+ string.gsub(/<num>/, '')
153
+ end
122
154
 
123
- def self.andition(string)
124
- sc = StringScanner.new(string)
125
- while(sc.scan_until(/<num>(\d+)( | and )<num>(\d+)(?=[^\w]|$)/i))
126
- if sc[2] =~ /and/ || sc[1].size > sc[3].size
127
- string[(sc.pos - sc.matched_size)..(sc.pos-1)] = '<num>' + (sc[1].to_i + sc[3].to_i).to_s
128
- sc.reset
129
- end
130
- end
131
- end
155
+ class << self
156
+ private
157
+ def andition(string)
158
+ sc = StringScanner.new(string)
159
+ while(sc.scan_until(/<num>(\d+)( | and )<num>(\d+)(?=[^\w]|$)/i))
160
+ if sc[2] =~ /and/ || sc[1].size > sc[3].size
161
+ string[(sc.pos - sc.matched_size)..(sc.pos-1)] = '<num>' + (sc[1].to_i + sc[3].to_i).to_s
162
+ sc.reset
163
+ end
164
+ end
165
+ end
166
+ end
132
167
 
133
168
  end
@@ -1,50 +1,37 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
+ # stub: numerizer 0.2.0 ruby lib
5
6
 
6
7
  Gem::Specification.new do |s|
7
- s.name = %q{numerizer}
8
- s.version = "0.1.1"
8
+ s.name = "numerizer"
9
+ s.version = "0.2.0"
9
10
 
10
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
11
13
  s.authors = ["John Duff"]
12
- s.date = %q{2010-01-01}
13
- s.description = %q{Numerizer is a gem to help with parsing numbers in natural language from strings (ex forty two). It was extracted from the awesome Chronic gem http://github.com/evaryont/chronic.}
14
- s.email = %q{duff.john@gmail.com}
14
+ s.date = "2014-04-23"
15
+ s.description = "Numerizer is a gem to help with parsing numbers in natural language from strings (ex forty two). It was extracted from the awesome Chronic gem http://github.com/evaryont/chronic."
16
+ s.email = "duff.john@gmail.com"
15
17
  s.extra_rdoc_files = [
16
18
  "LICENSE",
17
- "README.rdoc"
19
+ "README.rdoc"
18
20
  ]
19
21
  s.files = [
20
22
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "lib/numerizer.rb",
27
- "numerizer.gemspec",
28
- "test/test_helper.rb",
29
- "test/test_numerizer.rb"
30
- ]
31
- s.homepage = %q{http://github.com/jduff/numerizer}
32
- s.rdoc_options = ["--charset=UTF-8"]
33
- s.require_paths = ["lib"]
34
- s.rubygems_version = %q{1.3.5}
35
- s.summary = %q{Numerizer is a gem to help with parsing numbers in natural language from strings (ex forty two).}
36
- s.test_files = [
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/numerizer.rb",
28
+ "numerizer.gemspec",
37
29
  "test/test_helper.rb",
38
- "test/test_numerizer.rb"
30
+ "test/test_numerizer.rb"
39
31
  ]
40
-
41
- if s.respond_to? :specification_version then
42
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
- s.specification_version = 3
44
-
45
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
- else
47
- end
48
- else
49
- end
32
+ s.homepage = "http://github.com/jduff/numerizer"
33
+ s.licenses = ["MIT"]
34
+ s.rubygems_version = "2.2.2"
35
+ s.summary = "Numerizer is a gem to help with parsing numbers in natural language from strings (ex forty two)."
50
36
  end
37
+
@@ -1,92 +1,130 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
3
  class NumerizerTest < Test::Unit::TestCase
4
- def test_straight_parsing
5
- strings = { 1 => 'one',
6
- 5 => 'five',
7
- 10 => 'ten',
8
- 11 => 'eleven',
9
- 12 => 'twelve',
10
- 13 => 'thirteen',
11
- 14 => 'fourteen',
12
- 15 => 'fifteen',
13
- 16 => 'sixteen',
14
- 17 => 'seventeen',
15
- 18 => 'eighteen',
16
- 19 => 'nineteen',
17
- 20 => 'twenty',
18
- 27 => 'twenty seven',
19
- 31 => 'thirty-one',
20
- 41 => 'forty one',
21
- 42 => 'fourty two',
22
- 59 => 'fifty nine',
23
- 100 => 'a hundred',
24
- 100 => 'one hundred',
25
- 150 => 'one hundred and fifty',
26
- # 150 => 'one fifty',
27
- 200 => 'two-hundred',
28
- 500 => '5 hundred',
29
- 999 => 'nine hundred and ninety nine',
30
- 1_000 => 'one thousand',
31
- 1_200 => 'twelve hundred',
32
- 1_200 => 'one thousand two hundred',
33
- 17_000 => 'seventeen thousand',
4
+ def test_straight_parsing
5
+ strings = {
6
+ 1 => 'one',
7
+ 5 => 'five',
8
+ 10 => 'ten',
9
+ 11 => 'eleven',
10
+ 12 => 'twelve',
11
+ 13 => 'thirteen',
12
+ 14 => 'fourteen',
13
+ 15 => 'fifteen',
14
+ 16 => 'sixteen',
15
+ 17 => 'seventeen',
16
+ 18 => 'eighteen',
17
+ 19 => 'nineteen',
18
+ 20 => 'twenty',
19
+ 27 => 'twenty seven',
20
+ 31 => 'thirty-one',
21
+ 37 => 'thirty-seven',
22
+ 41 => 'forty one',
23
+ 42 => 'fourty two',
24
+ 59 => 'fifty nine',
25
+ 100 => 'a hundred',
26
+ 100 => 'one hundred',
27
+ 150 => 'one hundred and fifty',
28
+ # 150 => 'one fifty',
29
+ 200 => 'two-hundred',
30
+ 500 => '5 hundred',
31
+ 999 => 'nine hundred and ninety nine',
32
+ 1_000 => 'one thousand',
33
+ 1_200 => 'twelve hundred',
34
+ 1_200 => 'one thousand two hundred',
35
+ 17_000 => 'seventeen thousand',
34
36
  21_473 => 'twentyone-thousand-four-hundred-and-seventy-three',
35
- 74_002 => 'seventy four thousand and two',
36
- 99_999 => 'ninety nine thousand nine hundred ninety nine',
37
- 100_000 => '100 thousand',
38
- 250_000 => 'two hundred fifty thousand',
39
- 1_000_000 => 'one million',
40
- 1_250_007 => 'one million two hundred fifty thousand and seven',
41
- 1_000_000_000 => 'one billion',
42
- 1_000_000_001 => 'one billion and one' }
37
+ 74_002 => 'seventy four thousand and two',
38
+ 99_999 => 'ninety nine thousand nine hundred ninety nine',
39
+ 100_000 => '100 thousand',
40
+ 250_000 => 'two hundred fifty thousand',
41
+ 1_000_000 => 'one million',
42
+ 1_250_007 => 'one million two hundred fifty thousand and seven',
43
+ 1_000_000_000 => 'one billion',
44
+ 1_000_000_001 => 'one billion and one'
45
+ }
43
46
 
44
- strings.keys.sort.each do |key|
45
- assert_equal key, Numerizer.numerize(strings[key]).to_i
46
- end
47
-
48
- assert_equal "2.5", Numerizer.numerize("two and a half")
49
- assert_equal "1/2", Numerizer.numerize("one half")
50
- end
51
-
52
- def test_combined_double_digets
53
- assert_equal "21", Numerizer.numerize("twentyone")
54
- assert_equal "37", Numerizer.numerize("thirtyseven")
47
+ strings.keys.sort.each do |key|
48
+ assert_equal key, Numerizer.numerize(strings[key]).to_i
49
+ end
50
+
51
+ assert_equal "2.5", Numerizer.numerize("two and a half")
52
+ assert_equal "1/2", Numerizer.numerize("one half")
53
+ end
54
+
55
+ def test_combined_double_digets
56
+ assert_equal "21", Numerizer.numerize("twentyone")
57
+ assert_equal "37", Numerizer.numerize("thirtyseven")
55
58
  end
56
-
59
+
57
60
  def test_fractions_in_words
58
61
  assert_equal "1/4", Numerizer.numerize("1 quarter")
59
62
  assert_equal "1/4", Numerizer.numerize("one quarter")
60
63
  assert_equal "1/4", Numerizer.numerize("a quarter")
61
64
  assert_equal "1/8", Numerizer.numerize("one eighth")
62
-
65
+
63
66
  assert_equal "3/4", Numerizer.numerize("three quarters")
64
67
  assert_equal "2/4", Numerizer.numerize("two fourths")
65
68
  assert_equal "3/8", Numerizer.numerize("three eighths")
66
69
  end
67
-
70
+
68
71
  def test_fractional_addition
69
72
  assert_equal "1.25", Numerizer.numerize("one and a quarter")
70
73
  assert_equal "2.375", Numerizer.numerize("two and three eighths")
71
74
  assert_equal "3.5 hours", Numerizer.numerize("three and a half hours")
72
75
  end
73
-
76
+
74
77
  def test_word_with_a_number
75
78
  assert_equal "pennyweight", Numerizer.numerize("pennyweight")
76
79
  end
77
80
 
78
- def test_edges
79
- assert_equal "27 Oct 2006 7:30am", Numerizer.numerize("27 Oct 2006 7:30am")
80
- end
81
-
82
- def test_multiple_slashes_should_not_be_evaluated
83
- assert_equal '11/02/2007', Numerizer.numerize('11/02/2007')
81
+ def test_edges
82
+ assert_equal "27 Oct 2006 7:30am", Numerizer.numerize("27 Oct 2006 7:30am")
83
+ end
84
+
85
+ def test_multiple_slashes_should_not_be_evaluated
86
+ assert_equal '11/02/2007', Numerizer.numerize('11/02/2007')
84
87
  end
85
-
88
+
86
89
  def test_compatability
87
90
  assert_equal '1/2', Numerizer.numerize('1/2')
88
91
  assert_equal '05/06', Numerizer.numerize('05/06')
89
92
  assert_equal "3.5 hours", Numerizer.numerize("three and a half hours")
90
93
  end
91
94
 
95
+ def test_ordinal_strings
96
+ {
97
+ 'first' => '1st',
98
+ 'second' => 'second',
99
+ 'third' => '3rd',
100
+ 'fifth' => '5th',
101
+ 'seventh' => '7th',
102
+ 'eighth' => '8th',
103
+ 'tenth' => '10th',
104
+ 'eleventh' => '11th',
105
+ 'twelfth' => '12th',
106
+ 'thirteenth' => '13th',
107
+ 'sixteenth' => '16th',
108
+ 'twentieth' => '20th',
109
+ 'twenty-third' => '23rd',
110
+ 'thirtieth' => '30th',
111
+ 'thirty-first' => '31st',
112
+ 'fourtieth' => '40th',
113
+ 'fourty ninth' => '49th',
114
+ 'fiftieth' => '50th',
115
+ 'sixtieth' => '60th',
116
+ 'seventieth' => '70th',
117
+ 'eightieth' => '80th',
118
+ 'ninetieth' => '90th',
119
+ 'hundredth' => '100th',
120
+ 'thousandth' => '1000th',
121
+ 'millionth' => '1000000th',
122
+ 'billionth' => '1000000000th',
123
+ 'trillionth' => '1000000000000th',
124
+ 'first day month two' => '1st day month 2'
125
+ }.each do |key, val|
126
+ assert_equal val, Numerizer.numerize(key)
127
+ end
128
+ end
129
+
92
130
  end
metadata CHANGED
@@ -1,30 +1,25 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: numerizer
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - John Duff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2010-01-01 00:00:00 -05:00
13
- default_executable:
11
+ date: 2014-04-23 00:00:00.000000000 Z
14
12
  dependencies: []
15
-
16
- description: Numerizer is a gem to help with parsing numbers in natural language from strings (ex forty two). It was extracted from the awesome Chronic gem http://github.com/evaryont/chronic.
13
+ description: Numerizer is a gem to help with parsing numbers in natural language from
14
+ strings (ex forty two). It was extracted from the awesome Chronic gem http://github.com/evaryont/chronic.
17
15
  email: duff.john@gmail.com
18
16
  executables: []
19
-
20
17
  extensions: []
21
-
22
- extra_rdoc_files:
18
+ extra_rdoc_files:
23
19
  - LICENSE
24
20
  - README.rdoc
25
- files:
21
+ files:
26
22
  - .document
27
- - .gitignore
28
23
  - LICENSE
29
24
  - README.rdoc
30
25
  - Rakefile
@@ -33,34 +28,29 @@ files:
33
28
  - numerizer.gemspec
34
29
  - test/test_helper.rb
35
30
  - test/test_numerizer.rb
36
- has_rdoc: true
37
31
  homepage: http://github.com/jduff/numerizer
38
- licenses: []
39
-
32
+ licenses:
33
+ - MIT
34
+ metadata: {}
40
35
  post_install_message:
41
- rdoc_options:
42
- - --charset=UTF-8
43
- require_paths:
36
+ rdoc_options: []
37
+ require_paths:
44
38
  - lib
45
- required_ruby_version: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: "0"
50
- version:
51
- required_rubygems_version: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: "0"
56
- version:
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
57
49
  requirements: []
58
-
59
50
  rubyforge_project:
60
- rubygems_version: 1.3.5
51
+ rubygems_version: 2.2.2
61
52
  signing_key:
62
- specification_version: 3
63
- summary: Numerizer is a gem to help with parsing numbers in natural language from strings (ex forty two).
64
- test_files:
65
- - test/test_helper.rb
66
- - test/test_numerizer.rb
53
+ specification_version: 4
54
+ summary: Numerizer is a gem to help with parsing numbers in natural language from
55
+ strings (ex forty two).
56
+ test_files: []
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- *.sw?
2
- .DS_Store
3
- coverage
4
- rdoc
5
- pkg