gorilla 0.0.1.beta

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.
@@ -0,0 +1,10 @@
1
+ module Gorilla
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ PATCH = 1
6
+ BETA = 'beta'
7
+
8
+ VERSION = [MAJOR, MINOR, PATCH, BETA].compact.join('.').freeze
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ module Gorilla
2
+ class Volume < Unit
3
+ base :liter, :metric => true
4
+
5
+ unit :teaspoon, 0.00492892159, :liter
6
+ unit :tablespoon, 3, :teaspoon
7
+ unit :fluid_ounce, 2, :tablespoon
8
+ unit :cup, 8, :fluid_ounce
9
+ unit :pint, 2, :cup
10
+ unit :quart, 2, :pint
11
+ unit :gallon, 4, :quart
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ module Gorilla
2
+ class Weight < Unit
3
+ base :gram, :metric => true
4
+
5
+ unit :ounce, 28.3495231, :gram
6
+ unit :pound, 16, :ounce
7
+ end
8
+ end
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ class TemperatureScannerTest < Test::Unit::TestCase
5
+ def test_should_parse_celsius
6
+ regex = Gorilla::TemperatureScanner.rules[:celsius].regexp
7
+
8
+ [
9
+ '°C',
10
+ 'deg C',
11
+ 'degs C',
12
+ 'degrees C',
13
+ 'C',
14
+ 'Celsius',
15
+ 'celsius',
16
+ '℃'
17
+ ].each { |unit| assert_match regex, unit }
18
+
19
+ %w(
20
+ c
21
+ ).each { |bad| assert_no_match regex, bad }
22
+ end
23
+
24
+ def test_should_parse_fahrenheit
25
+ regex = Gorilla::TemperatureScanner.rules[:fahrenheit].regexp
26
+
27
+ [
28
+ '°F',
29
+ 'deg F',
30
+ 'degs F',
31
+ 'degrees F',
32
+ 'F',
33
+ 'Fahrenheit',
34
+ 'fahrenheit',
35
+ '℉'
36
+ ].each { |unit| assert_match regex, unit }
37
+
38
+ %w(
39
+ f
40
+ ).each { |bad| assert_no_match regex, bad }
41
+ end
42
+ end
@@ -0,0 +1,123 @@
1
+ require 'test_helper'
2
+
3
+ class TimeScannerTest < Test::Unit::TestCase
4
+ def test_should_parse_seconds
5
+ regex = Gorilla::TimeScanner.rules[:second].regexp
6
+ durations = %w(
7
+ s sec second seconds secs
8
+ )
9
+
10
+ durations.each do |duration|
11
+ assert_match regex, duration
12
+ assert_match regex, duration.capitalize
13
+ assert_match regex, duration.upcase
14
+ end
15
+
16
+ %w(
17
+ ss
18
+ ).each { |bad| assert_no_match regex, bad }
19
+ end
20
+
21
+ def test_should_parse_minutes
22
+ regex = Gorilla::TimeScanner.rules[:minute].regexp
23
+ durations = %w(
24
+ m min mins minute minutes
25
+ )
26
+
27
+ durations.each do |duration|
28
+ assert_match regex, duration
29
+ assert_match regex, duration.capitalize
30
+ assert_match regex, duration.upcase
31
+ end
32
+
33
+ %w(
34
+ ms
35
+ ).each { |bad| assert_no_match regex, bad }
36
+ end
37
+
38
+ def test_should_parse_hours
39
+ regex = Gorilla::TimeScanner.rules[:hour].regexp
40
+ durations = %w(
41
+ h hour hours hr hrs
42
+ )
43
+
44
+ durations.each do |duration|
45
+ assert_match regex, duration
46
+ assert_match regex, duration.capitalize
47
+ assert_match regex, duration.upcase
48
+ end
49
+
50
+ %w(
51
+ hs
52
+ ).each { |bad| assert_no_match regex, bad }
53
+ end
54
+
55
+ def test_should_parse_days
56
+ regex = Gorilla::TimeScanner.rules[:day].regexp
57
+ durations = %w(
58
+ d day days
59
+ )
60
+
61
+ durations.each do |duration|
62
+ assert_match regex, duration
63
+ assert_match regex, duration.capitalize
64
+ assert_match regex, duration.upcase
65
+ end
66
+
67
+ %w(
68
+ ds
69
+ ).each { |bad| assert_no_match regex, bad }
70
+ end
71
+
72
+ def test_should_scan
73
+ {
74
+ ["1h30m",
75
+ "1hr, 30min",
76
+ "1 H 30 M"] => [1.hour, 30.minutes],
77
+ ["1:30",
78
+ "one hour and thirty minutes",
79
+ # "hour plus thirty",
80
+ "an hour and a half"] => [1.5.hours],
81
+ ["2h20m",
82
+ "2hr, 20min",
83
+ "2 H 20 M"] => [2.hours, 20.minutes],
84
+ [# "two hours and twenty",
85
+ "2:20"] => [2.hours + 20.minutes],
86
+ ["0 min", "zero min"] => [0.minutes],
87
+ "one hundred and eighty-two minutes, fifteen seconds" =>
88
+ [182.minutes, 15.seconds],
89
+ "40 to 45 min" => [40.minutes..45.minutes],
90
+ "between 18 and 22 hours" => [18.hours..22.hours],
91
+ "Bake at 325 for 45 min" => [45.minutes],
92
+ "Let dough rest 4.5 hours" => [4.5.hours],
93
+ "Nineteen hundred minutes" => [1_900.minutes],
94
+ "a half hour" => [0.5.hours],
95
+ "3 and a half hours" => [3.5.hours],
96
+ # "3 hours and 15" => [3.hours, 15.minutes],
97
+ "3 1/2 hours" => [3.5.hours],
98
+ "half day" => [0.5.days],
99
+ <<LONGER => [10.min, 8.min, 12.min, 22.min..25.min, 10.min]
100
+ Turn the oven on to 400 degrees. Meanwhile, chop onions and fry till
101
+ translucent, about 10 minutes. Add mushrooms and cook water out of them,
102
+ another 8 minutes. Boil until reduced (12 minutes). Put in oven and bake for
103
+ 22 to 25 minutes till done. Let rest 10 minutes.
104
+ LONGER
105
+ }.each do |inputs, parsed|
106
+ [*inputs].each do |input|
107
+ assert_equal parsed, Gorilla::TimeScanner.scan(input), input
108
+ end
109
+ end
110
+ end
111
+
112
+ def test_should_parse_iso8601
113
+ {
114
+ "P1Y2W3DT4H5M6.7S" =>
115
+ 1.year + 2.weeks + 3.days + 4.hours + 5.minutes + 6.7.seconds,
116
+ "PT15M" => 15.minutes,
117
+ "PT1H30M" => 1.5.hours,
118
+ "P1DY3" => nil # Invalid.
119
+ }.each do |input, parsed|
120
+ assert_equal parsed, Gorilla::TimeScanner.parse(input), input
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,148 @@
1
+ require 'test_helper'
2
+
3
+ class VolumeScannerTest < Test::Unit::TestCase
4
+ def test_should_parse_cups
5
+ regex = Gorilla::VolumeScanner.rules[:cup].regexp
6
+ units = %w(
7
+ c cp cu cup
8
+ )
9
+
10
+ units.each do |unit|
11
+ assert_match regex, unit
12
+ assert_match regex, unit.capitalize
13
+ assert_match regex, unit.pluralize
14
+ assert_match regex, unit.capitalize.pluralize
15
+ end
16
+ end
17
+
18
+ def test_should_parse_gallons
19
+ regex = Gorilla::VolumeScanner.rules[:gallon].regexp
20
+ units = %w(
21
+ gal gallon galn gl gln
22
+ )
23
+
24
+ units.each do |unit|
25
+ assert_match regex, unit
26
+ assert_match regex, unit.capitalize
27
+ assert_match regex, unit.pluralize
28
+ assert_match regex, unit.capitalize.pluralize
29
+ end
30
+
31
+ %w(
32
+ g glon
33
+ ).each { |bad| assert_no_match regex, bad }
34
+ end
35
+
36
+ def test_should_parse_liters
37
+ regex = Gorilla::VolumeScanner.rules[:liter].regexp
38
+ units = %w(
39
+ l liter litr litre lr lt ltr
40
+ )
41
+
42
+ units.each do |unit|
43
+ assert_match regex, unit
44
+ assert_match regex, unit.capitalize
45
+ assert_match regex, unit.pluralize
46
+ assert_match regex, unit.capitalize.pluralize
47
+ end
48
+
49
+ %w(
50
+ lier lire lit lite
51
+ ).each { |bad| assert_no_match regex, bad }
52
+ end
53
+
54
+ def test_should_parse_fluid_ounces
55
+ regex = Gorilla::VolumeScanner.rules[:fluid_ounce].regexp
56
+ units = %w(
57
+ ounce oz
58
+ )
59
+
60
+ units.each do |unit|
61
+ assert_match regex, unit
62
+ assert_match regex, unit.capitalize
63
+ assert_match regex, unit.pluralize
64
+ assert_match regex, unit.capitalize.pluralize
65
+ end
66
+
67
+ %w(
68
+ onc once one ounc
69
+ ).each { |bad| assert_no_match regex, bad }
70
+ end
71
+
72
+ def test_should_parse_pints
73
+ regex = Gorilla::VolumeScanner.rules[:pint].regexp
74
+ units = %w(
75
+ p pint pnt pt
76
+ )
77
+
78
+ units.each do |unit|
79
+ assert_match regex, unit
80
+ assert_match regex, unit.capitalize
81
+ assert_match regex, unit.pluralize
82
+ assert_match regex, unit.capitalize.pluralize
83
+ end
84
+
85
+ %w(
86
+ pi pin
87
+ ).each { |bad| assert_no_match regex, bad }
88
+ end
89
+
90
+ def test_should_parse_quarts
91
+ regex = Gorilla::VolumeScanner.rules[:quart].regexp
92
+ units = %w(
93
+ qrt qt quart
94
+ )
95
+
96
+ units.each do |unit|
97
+ assert_match regex, unit
98
+ assert_match regex, unit.capitalize
99
+ assert_match regex, unit.pluralize
100
+ assert_match regex, unit.capitalize.pluralize
101
+ end
102
+
103
+ %w(
104
+ qart qat qua quar qurt qut
105
+ ).each { |bad| assert_no_match regex, bad }
106
+ end
107
+
108
+ def test_should_parse_tablespoons
109
+ regex = Gorilla::VolumeScanner.rules[:tablespoon].regexp
110
+ assert_match regex, "T"
111
+
112
+ units = %w(
113
+ tablesp tablespn tablespoon tablsp tb tbls tblsp tblspn tblspoon tbs tbsp
114
+ tbspn tbspoon
115
+ )
116
+
117
+ units.each do |unit|
118
+ assert_match regex, unit
119
+ assert_match regex, unit.capitalize
120
+ assert_match regex, unit.pluralize
121
+ assert_match regex, unit.capitalize.pluralize
122
+ end
123
+
124
+ %w(
125
+ t table tables tsp tspn tspoon
126
+ ).each { |bad| assert_no_match regex, bad }
127
+ end
128
+
129
+ def test_should_parse_teaspoons
130
+ regex = Gorilla::VolumeScanner.rules[:teaspoon].regexp
131
+ assert_match regex, "t"
132
+
133
+ units = %w(
134
+ teasp teaspoon teaspn tsp
135
+ )
136
+
137
+ units.each do |unit|
138
+ assert_match regex, unit
139
+ assert_match regex, unit.capitalize
140
+ assert_match regex, unit.pluralize
141
+ assert_match regex, unit.capitalize.pluralize
142
+ end
143
+
144
+ %w(
145
+ T
146
+ ).each { |bad| assert_no_match regex, bad }
147
+ end
148
+ end
@@ -0,0 +1,57 @@
1
+ require 'test_helper'
2
+
3
+ class WeightScannerTest < Test::Unit::TestCase
4
+ def test_should_parse_grams
5
+ regex = Gorilla::WeightScanner.rules[:gram].regexp
6
+ units = %w(
7
+ g gm gr gram
8
+ )
9
+
10
+ units.each do |unit|
11
+ assert_match regex, unit
12
+ assert_match regex, unit.capitalize
13
+ assert_match regex, unit.pluralize
14
+ assert_match regex, unit.capitalize.pluralize
15
+ end
16
+
17
+ %w(
18
+ ga gra
19
+ ).each { |bad| assert_no_match regex, bad }
20
+ end
21
+
22
+ def test_should_parse_ounces
23
+ regex = Gorilla::WeightScanner.rules[:ounce].regexp
24
+ units = %w(
25
+ ounce oz
26
+ )
27
+
28
+ units.each do |unit|
29
+ assert_match regex, unit
30
+ assert_match regex, unit.capitalize
31
+ assert_match regex, unit.pluralize
32
+ assert_match regex, unit.capitalize.pluralize
33
+ end
34
+
35
+ %w(
36
+ onc once one ounc
37
+ ).each { |bad| assert_no_match regex, bad }
38
+ end
39
+
40
+ def test_should_parse_pounds
41
+ regex = Gorilla::WeightScanner.rules[:pound].regexp
42
+ units = %w(
43
+ lb pd pnd pound #
44
+ )
45
+
46
+ units.each do |unit|
47
+ assert_match regex, unit
48
+ assert_match regex, unit.capitalize
49
+ assert_match regex, unit.pluralize
50
+ assert_match regex, unit.capitalize.pluralize
51
+ end
52
+
53
+ %w(
54
+ p pn
55
+ ).each { |bad| assert_no_match regex, bad }
56
+ end
57
+ end
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ class TimeTest < Test::Unit::TestCase
4
+ def test_should_format_iso8601
5
+ {
6
+ 1.5.minutes => "PT1M30S",
7
+ 45.minutes => "PT45M",
8
+ 90.minutes => "PT1H30M",
9
+ 1.5.days => "P1DT12H"
10
+ }.each_pair do |duration, iso8601|
11
+ assert_equal iso8601, duration.iso8601
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ require 'test/unit'
2
+ require 'gorilla/all'
3
+ require 'gorilla/scanners'
4
+ require 'gorilla/core_ext'
5
+
6
+ class String
7
+ def pluralize
8
+ end_with?('s') ? to_s : "#{to_s}s"
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gorilla
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: true
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ - beta
10
+ version: 0.0.1.beta
11
+ platform: ruby
12
+ authors:
13
+ - Stephen Celis
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-15 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rdoctest
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: scantron
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 0
44
+ version: "0"
45
+ type: :development
46
+ version_requirements: *id002
47
+ description: A unit conversion and parsing library.
48
+ email: stephen@stephencelis.com
49
+ executables: []
50
+
51
+ extensions: []
52
+
53
+ extra_rdoc_files:
54
+ - README.rdoc
55
+ files:
56
+ - README.rdoc
57
+ - Rakefile
58
+ - lib/gorilla/all.rb
59
+ - lib/gorilla/core_ext.rb
60
+ - lib/gorilla/scanner.rb
61
+ - lib/gorilla/scanners/omni_scanner.rb
62
+ - lib/gorilla/scanners/temperature_scanner.rb
63
+ - lib/gorilla/scanners/time_scanner.rb
64
+ - lib/gorilla/scanners/volume_scanner.rb
65
+ - lib/gorilla/scanners/weight_scanner.rb
66
+ - lib/gorilla/scanners.rb
67
+ - lib/gorilla/scantron_ext.rb
68
+ - lib/gorilla/temperature.rb
69
+ - lib/gorilla/time.rb
70
+ - lib/gorilla/unit.rb
71
+ - lib/gorilla/version.rb
72
+ - lib/gorilla/volume.rb
73
+ - lib/gorilla/weight.rb
74
+ - lib/gorilla.rb
75
+ - test/gorilla/scanners/temperature_scanner_test.rb
76
+ - test/gorilla/scanners/time_scanner_test.rb
77
+ - test/gorilla/scanners/volume_scanner_test.rb
78
+ - test/gorilla/scanners/weight_scanner_test.rb
79
+ - test/gorilla/time_test.rb
80
+ - test/test_helper.rb
81
+ has_rdoc: true
82
+ homepage: http://github.com/stephencelis/gorilla
83
+ licenses: []
84
+
85
+ post_install_message:
86
+ rdoc_options:
87
+ - --main
88
+ - README.rdoc
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">"
103
+ - !ruby/object:Gem::Version
104
+ segments:
105
+ - 1
106
+ - 3
107
+ - 1
108
+ version: 1.3.1
109
+ requirements: []
110
+
111
+ rubyforge_project:
112
+ rubygems_version: 1.3.7
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: Big, strong, intelligent unit conversions.
116
+ test_files:
117
+ - test/gorilla/scanners/temperature_scanner_test.rb
118
+ - test/gorilla/scanners/time_scanner_test.rb
119
+ - test/gorilla/scanners/volume_scanner_test.rb
120
+ - test/gorilla/scanners/weight_scanner_test.rb
121
+ - test/gorilla/time_test.rb
122
+ - test/test_helper.rb