numeral 0.1.0 → 0.2.0
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.
- data/.rvmrc +1 -0
- data/VERSION +1 -1
- data/lib/numeral.rb +3 -3
- data/spec/numeral_spec.rb +17 -12
- metadata +11 -3
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.8.7-p174
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/numeral.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Numeral
|
2
|
-
def
|
3
|
-
return
|
2
|
+
def parse_num(text)
|
3
|
+
return parse_natural_num(text) if text[/[a-z|A-Z]/]
|
4
4
|
numerator, denominator = text.split('/')
|
5
5
|
return numerator.to_f if numerator.include?('.')
|
6
6
|
denominator ||= 1
|
7
7
|
Rational(numerator.to_i, denominator.to_i)
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def parse_natural_num(text)
|
11
11
|
[
|
12
12
|
'zero',
|
13
13
|
'one',
|
data/spec/numeral_spec.rb
CHANGED
@@ -2,30 +2,35 @@ require 'spec_helper'
|
|
2
2
|
require 'rational'
|
3
3
|
|
4
4
|
describe Numeral do
|
5
|
+
include Numeral
|
6
|
+
|
7
|
+
it "returns nil if input cannot be parsed" do
|
8
|
+
parse_num("foobar").should be_nil
|
9
|
+
end
|
10
|
+
|
5
11
|
describe "parses" do
|
6
|
-
include Numeral
|
7
12
|
|
8
13
|
it "digits" do
|
9
|
-
|
10
|
-
|
14
|
+
parse_num("1").should == 1
|
15
|
+
parse_num("12").should == 12
|
11
16
|
end
|
12
17
|
|
13
18
|
it "fractions" do
|
14
|
-
|
15
|
-
|
19
|
+
parse_num("2/3").should == Rational(2,3)
|
20
|
+
parse_num("3/4").should == 0.75
|
16
21
|
end
|
17
22
|
|
18
23
|
it "decimals" do
|
19
|
-
|
20
|
-
|
24
|
+
parse_num("0.5").should == 0.5
|
25
|
+
parse_num(".5").should == 0.5
|
21
26
|
end
|
22
27
|
|
23
28
|
it "natural words" do
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
parse_num("zero").should == 0
|
30
|
+
parse_num("One").should == 1
|
31
|
+
parse_num("TEN").should == 10
|
32
|
+
parse_num("thirteen").should == 13
|
33
|
+
parse_num("twenty").should == 20
|
29
34
|
end
|
30
35
|
end
|
31
36
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numeral
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
+
- 2
|
8
9
|
- 0
|
9
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Ben Rady
|
@@ -21,9 +22,11 @@ dependencies:
|
|
21
22
|
name: rspec
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
27
30
|
segments:
|
28
31
|
- 1
|
29
32
|
- 2
|
@@ -43,6 +46,7 @@ extra_rdoc_files:
|
|
43
46
|
files:
|
44
47
|
- .document
|
45
48
|
- .gitignore
|
49
|
+
- .rvmrc
|
46
50
|
- LICENSE
|
47
51
|
- README.rdoc
|
48
52
|
- Rakefile
|
@@ -62,23 +66,27 @@ rdoc_options:
|
|
62
66
|
require_paths:
|
63
67
|
- lib
|
64
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
65
70
|
requirements:
|
66
71
|
- - ">="
|
67
72
|
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
68
74
|
segments:
|
69
75
|
- 0
|
70
76
|
version: "0"
|
71
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
72
79
|
requirements:
|
73
80
|
- - ">="
|
74
81
|
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
75
83
|
segments:
|
76
84
|
- 0
|
77
85
|
version: "0"
|
78
86
|
requirements: []
|
79
87
|
|
80
88
|
rubyforge_project:
|
81
|
-
rubygems_version: 1.3.
|
89
|
+
rubygems_version: 1.3.7
|
82
90
|
signing_key:
|
83
91
|
specification_version: 3
|
84
92
|
summary: Converts natural text to numbers
|