chronic_duration 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Gemfile.lock +2 -0
- data/VERSION +1 -1
- data/chronic_duration.gemspec +4 -2
- metadata +26 -12
- data/lib/numerizer.rb +0 -98
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -7,6 +7,7 @@ GEM
|
|
7
7
|
bundler (~> 1.0.0)
|
8
8
|
git (>= 1.2.5)
|
9
9
|
rake
|
10
|
+
numerizer (0.1.1)
|
10
11
|
rake (0.8.7)
|
11
12
|
rcov (0.9.9)
|
12
13
|
rspec (2.3.0)
|
@@ -24,5 +25,6 @@ PLATFORMS
|
|
24
25
|
DEPENDENCIES
|
25
26
|
bundler (~> 1.0.0)
|
26
27
|
jeweler (~> 1.5.2)
|
28
|
+
numerizer (~> 0.1.1)
|
27
29
|
rcov
|
28
30
|
rspec (~> 2.3.0)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.4
|
data/chronic_duration.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{chronic_duration}
|
8
|
-
s.version = "0.9.
|
8
|
+
s.version = "0.9.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["hpoydar"]
|
@@ -24,7 +24,6 @@ Gem::Specification.new do |s|
|
|
24
24
|
"VERSION",
|
25
25
|
"chronic_duration.gemspec",
|
26
26
|
"lib/chronic_duration.rb",
|
27
|
-
"lib/numerizer.rb",
|
28
27
|
"spec/chronic_duration_spec.rb"
|
29
28
|
]
|
30
29
|
s.homepage = %q{http://github.com/hpoydar/chronic_duration}
|
@@ -41,17 +40,20 @@ Gem::Specification.new do |s|
|
|
41
40
|
s.specification_version = 3
|
42
41
|
|
43
42
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_runtime_dependency(%q<numerizer>, ["~> 0.1.1"])
|
44
44
|
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
45
45
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
46
46
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
47
47
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
48
48
|
else
|
49
|
+
s.add_dependency(%q<numerizer>, ["~> 0.1.1"])
|
49
50
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
50
51
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
51
52
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
52
53
|
s.add_dependency(%q<rcov>, [">= 0"])
|
53
54
|
end
|
54
55
|
else
|
56
|
+
s.add_dependency(%q<numerizer>, ["~> 0.1.1"])
|
55
57
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
56
58
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
59
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 4
|
9
|
+
version: 0.9.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- hpoydar
|
@@ -18,8 +18,23 @@ date: 2011-03-29 00:00:00 -04:00
|
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
21
|
+
name: numerizer
|
22
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 1
|
30
|
+
- 1
|
31
|
+
version: 0.1.1
|
32
|
+
type: :runtime
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
23
38
|
none: false
|
24
39
|
requirements:
|
25
40
|
- - ~>
|
@@ -31,10 +46,10 @@ dependencies:
|
|
31
46
|
version: 2.3.0
|
32
47
|
type: :development
|
33
48
|
prerelease: false
|
34
|
-
version_requirements: *
|
49
|
+
version_requirements: *id002
|
35
50
|
- !ruby/object:Gem::Dependency
|
36
51
|
name: bundler
|
37
|
-
requirement: &
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
38
53
|
none: false
|
39
54
|
requirements:
|
40
55
|
- - ~>
|
@@ -46,10 +61,10 @@ dependencies:
|
|
46
61
|
version: 1.0.0
|
47
62
|
type: :development
|
48
63
|
prerelease: false
|
49
|
-
version_requirements: *
|
64
|
+
version_requirements: *id003
|
50
65
|
- !ruby/object:Gem::Dependency
|
51
66
|
name: jeweler
|
52
|
-
requirement: &
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
68
|
none: false
|
54
69
|
requirements:
|
55
70
|
- - ~>
|
@@ -61,10 +76,10 @@ dependencies:
|
|
61
76
|
version: 1.5.2
|
62
77
|
type: :development
|
63
78
|
prerelease: false
|
64
|
-
version_requirements: *
|
79
|
+
version_requirements: *id004
|
65
80
|
- !ruby/object:Gem::Dependency
|
66
81
|
name: rcov
|
67
|
-
requirement: &
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
68
83
|
none: false
|
69
84
|
requirements:
|
70
85
|
- - ">="
|
@@ -74,7 +89,7 @@ dependencies:
|
|
74
89
|
version: "0"
|
75
90
|
type: :development
|
76
91
|
prerelease: false
|
77
|
-
version_requirements: *
|
92
|
+
version_requirements: *id005
|
78
93
|
description: A simple Ruby natural language parser for elapsed time. (For example, 4 hours and 30 minutes, 6 minutes 4 seconds, 3 days, etc.) Returns all results in seconds. Will return an integer unless you get tricky and need a float. (4 minutes and 13.47 seconds, for example.) The reverse can also be performed via the output method.
|
79
94
|
email: hpoydar@gmail.com
|
80
95
|
executables: []
|
@@ -92,7 +107,6 @@ files:
|
|
92
107
|
- VERSION
|
93
108
|
- chronic_duration.gemspec
|
94
109
|
- lib/chronic_duration.rb
|
95
|
-
- lib/numerizer.rb
|
96
110
|
- spec/chronic_duration_spec.rb
|
97
111
|
has_rdoc: true
|
98
112
|
homepage: http://github.com/hpoydar/chronic_duration
|
@@ -108,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
122
|
requirements:
|
109
123
|
- - ">="
|
110
124
|
- !ruby/object:Gem::Version
|
111
|
-
hash: -
|
125
|
+
hash: -2010383347137411126
|
112
126
|
segments:
|
113
127
|
- 0
|
114
128
|
version: "0"
|
data/lib/numerizer.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
require 'strscan'
|
2
|
-
|
3
|
-
class Numerizer
|
4
|
-
|
5
|
-
DIRECT_NUMS = [
|
6
|
-
['eleven', '11'],
|
7
|
-
['twelve', '12'],
|
8
|
-
['thirteen', '13'],
|
9
|
-
['fourteen', '14'],
|
10
|
-
['fifteen', '15'],
|
11
|
-
['sixteen', '16'],
|
12
|
-
['seventeen', '17'],
|
13
|
-
['eighteen', '18'],
|
14
|
-
['nineteen', '19'],
|
15
|
-
['ninteen', '19'], # Common mis-spelling
|
16
|
-
['zero', '0'],
|
17
|
-
['one', '1'],
|
18
|
-
['two', '2'],
|
19
|
-
['three', '3'],
|
20
|
-
['four(\W|$)', '4\1'], # The weird regex is so that it matches four but not fourty
|
21
|
-
['five', '5'],
|
22
|
-
['six(\W|$)', '6\1'],
|
23
|
-
['seven(\W|$)', '7\1'],
|
24
|
-
['eight(\W|$)', '8\1'],
|
25
|
-
['nine(\W|$)', '9\1'],
|
26
|
-
['ten', '10'],
|
27
|
-
['\ba[\b^$]', '1'] # doesn't make sense for an 'a' at the end to be a 1
|
28
|
-
]
|
29
|
-
|
30
|
-
TEN_PREFIXES = [ ['twenty', 20],
|
31
|
-
['thirty', 30],
|
32
|
-
['forty', 40],
|
33
|
-
['fourty', 40], # Common misspelling
|
34
|
-
['fifty', 50],
|
35
|
-
['sixty', 60],
|
36
|
-
['seventy', 70],
|
37
|
-
['eighty', 80],
|
38
|
-
['ninety', 90]
|
39
|
-
]
|
40
|
-
|
41
|
-
BIG_PREFIXES = [ ['hundred', 100],
|
42
|
-
['thousand', 1000],
|
43
|
-
['million', 1_000_000],
|
44
|
-
['billion', 1_000_000_000],
|
45
|
-
['trillion', 1_000_000_000_000],
|
46
|
-
]
|
47
|
-
|
48
|
-
def self.numerize(string)
|
49
|
-
string = string.dup
|
50
|
-
|
51
|
-
# preprocess
|
52
|
-
string.gsub!(/ +|([^\d])-([^\d])/, '\1 \2') # will mutilate hyphenated-words but shouldn't matter for date extraction
|
53
|
-
string.gsub!(/a half/, 'haAlf') # take the 'a' out so it doesn't turn into a 1, save the half for the end
|
54
|
-
|
55
|
-
# easy/direct replacements
|
56
|
-
|
57
|
-
DIRECT_NUMS.each do |dn|
|
58
|
-
string.gsub!(/#{dn[0]}/i, '<num>' + dn[1])
|
59
|
-
end
|
60
|
-
|
61
|
-
# ten, twenty, etc.
|
62
|
-
|
63
|
-
TEN_PREFIXES.each do |tp|
|
64
|
-
string.gsub!(/(?:#{tp[0]}) *<num>(\d(?=[^\d]|$))*/i) { '<num>' + (tp[1] + $1.to_i).to_s }
|
65
|
-
end
|
66
|
-
|
67
|
-
TEN_PREFIXES.each do |tp|
|
68
|
-
string.gsub!(/#{tp[0]}/i) { '<num>' + tp[1].to_s }
|
69
|
-
end
|
70
|
-
|
71
|
-
# hundreds, thousands, millions, etc.
|
72
|
-
|
73
|
-
BIG_PREFIXES.each do |bp|
|
74
|
-
string.gsub!(/(?:<num>)?(\d*) *#{bp[0]}/i) { '<num>' + (bp[1] * $1.to_i).to_s}
|
75
|
-
andition(string)
|
76
|
-
end
|
77
|
-
|
78
|
-
# fractional addition
|
79
|
-
# I'm not combining this with the previous block as using float addition complicates the strings
|
80
|
-
# (with extraneous .0's and such )
|
81
|
-
string.gsub!(/(\d+)(?: | and |-)*haAlf/i) { ($1.to_f + 0.5).to_s }
|
82
|
-
|
83
|
-
string.gsub(/<num>/, '')
|
84
|
-
end
|
85
|
-
|
86
|
-
private
|
87
|
-
|
88
|
-
def self.andition(string)
|
89
|
-
sc = StringScanner.new(string)
|
90
|
-
while(sc.scan_until(/<num>(\d+)( | and )<num>(\d+)(?=[^\w]|$)/i))
|
91
|
-
if sc[2] =~ /and/ || sc[1].size > sc[3].size
|
92
|
-
string[(sc.pos - sc.matched_size)..(sc.pos-1)] = '<num>' + (sc[1].to_i + sc[3].to_i).to_s
|
93
|
-
sc.reset
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|