ruby-measurement 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/.travis.yml +4 -0
  2. data/CHANGELOG.md +21 -0
  3. data/README.md +2 -0
  4. data/Rakefile +3 -0
  5. data/lib/ruby-measurement/definitions/metric.rb +1 -0
  6. data/lib/ruby-measurement/definitions/metric/capacity.rb +12 -82
  7. data/lib/ruby-measurement/definitions/metric/volume.rb +82 -12
  8. data/lib/ruby-measurement/definitions/us_customary.rb +1 -0
  9. data/lib/ruby-measurement/definitions/us_customary/capacity.rb +29 -0
  10. data/lib/ruby-measurement/definitions/us_customary/length.rb +0 -20
  11. data/lib/ruby-measurement/definitions/us_customary/weight.rb +6 -6
  12. data/lib/ruby-measurement/measurement.rb +5 -14
  13. data/lib/ruby-measurement/unit.rb +52 -11
  14. data/lib/ruby-measurement/version.rb +1 -1
  15. data/ruby-measurement.gemspec +1 -0
  16. data/spec/ruby-measurement/definitions/metric/area_spec.rb +69 -0
  17. data/spec/ruby-measurement/definitions/metric/capacity_spec.rb +41 -0
  18. data/spec/ruby-measurement/definitions/metric/length_spec.rb +261 -0
  19. data/spec/ruby-measurement/definitions/metric/volume_spec.rb +261 -0
  20. data/spec/ruby-measurement/definitions/metric/weight_spec.rb +325 -0
  21. data/spec/ruby-measurement/definitions/us_customary/area_spec.rb +149 -0
  22. data/spec/ruby-measurement/definitions/us_customary/capacity_spec.rb +69 -0
  23. data/spec/ruby-measurement/definitions/us_customary/length_spec.rb +261 -0
  24. data/spec/ruby-measurement/definitions/us_customary/volume_spec.rb +201 -0
  25. data/spec/ruby-measurement/definitions/us_customary/weight_spec.rb +149 -0
  26. data/spec/ruby-measurement/measurement_spec.rb +342 -0
  27. data/spec/ruby-measurement/unit_builder_spec.rb +102 -0
  28. data/spec/ruby-measurement/unit_spec.rb +120 -0
  29. data/spec/spec_helper.rb +5 -0
  30. data/tasks/rspec.rake +6 -0
  31. metadata +48 -5
@@ -0,0 +1,149 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Measurement do
6
+ describe 'square miles' do
7
+ subject { Measurement.parse('1 mi²') }
8
+
9
+ it 'converts to square furlongs' do
10
+ subject.convert_to(:fur2).quantity.should eq 64
11
+ end
12
+
13
+ it 'converts to square chains' do
14
+ subject.convert_to(:ch2).quantity.should eq 6_400
15
+ end
16
+
17
+ it 'converts to square yards' do
18
+ subject.convert_to(:yd2).quantity.should eq 3_097_600
19
+ end
20
+
21
+ it 'converts to square feet' do
22
+ subject.convert_to(:ft2).quantity.should eq 27_878_400
23
+ end
24
+
25
+ it 'converts to square inches' do
26
+ subject.convert_to(:in2).quantity.should eq 4_014_489_600
27
+ end
28
+ end
29
+
30
+ describe 'square furlongs' do
31
+ subject { Measurement.parse('64 fur²') }
32
+
33
+ it 'converts to square miles' do
34
+ subject.convert_to(:mi2).quantity.should eq 1
35
+ end
36
+
37
+ it 'converts to square chains' do
38
+ subject.convert_to(:ch2).quantity.should eq 6_400
39
+ end
40
+
41
+ it 'converts to square yards' do
42
+ subject.convert_to(:yd2).quantity.should eq 3_097_600
43
+ end
44
+
45
+ it 'converts to square feet' do
46
+ subject.convert_to(:ft2).quantity.should eq 27_878_400
47
+ end
48
+
49
+ it 'converts to square inches' do
50
+ subject.convert_to(:in2).quantity.should eq 4_014_489_600
51
+ end
52
+ end
53
+
54
+ describe 'square chains' do
55
+ subject { Measurement.parse('6400 ch²') }
56
+
57
+ it 'converts to square miles' do
58
+ subject.convert_to(:mi2).quantity.should eq 1
59
+ end
60
+
61
+ it 'converts to square furlongs' do
62
+ subject.convert_to(:fur2).quantity.should eq 64
63
+ end
64
+
65
+ it 'converts to square yards' do
66
+ subject.convert_to(:yd2).quantity.should eq 3_097_600
67
+ end
68
+
69
+ it 'converts to square feet' do
70
+ subject.convert_to(:ft2).quantity.should eq 27_878_400
71
+ end
72
+
73
+ it 'converts to square inches' do
74
+ subject.convert_to(:in2).quantity.should eq 4_014_489_600
75
+ end
76
+ end
77
+
78
+ describe 'square yards' do
79
+ subject { Measurement.parse('3097600 yd²') }
80
+
81
+ it 'converts to square miles' do
82
+ subject.convert_to(:mi2).quantity.should eq 1
83
+ end
84
+
85
+ it 'converts to square furlongs' do
86
+ subject.convert_to(:fur2).quantity.should eq 64
87
+ end
88
+
89
+ it 'converts to square chains' do
90
+ subject.convert_to(:ch2).quantity.should eq 6_400
91
+ end
92
+
93
+ it 'converts to square feet' do
94
+ subject.convert_to(:ft2).quantity.should eq 27_878_400
95
+ end
96
+
97
+ it 'converts to square inches' do
98
+ subject.convert_to(:in2).quantity.should eq 4_014_489_600
99
+ end
100
+ end
101
+
102
+ describe 'square feet' do
103
+ subject { Measurement.parse('27878400 ft²') }
104
+
105
+ it 'converts to square miles' do
106
+ subject.convert_to(:mi2).quantity.should eq 1
107
+ end
108
+
109
+ it 'converts to square furlongs' do
110
+ subject.convert_to(:fur2).quantity.should eq 64
111
+ end
112
+
113
+ it 'converts to square chains' do
114
+ subject.convert_to(:ch2).quantity.should eq 6_400
115
+ end
116
+
117
+ it 'converts to square yards' do
118
+ subject.convert_to(:yd2).quantity.should eq 3_097_600
119
+ end
120
+
121
+ it 'converts to square inches' do
122
+ subject.convert_to(:in2).quantity.should eq 4_014_489_600
123
+ end
124
+ end
125
+
126
+ describe 'square inches' do
127
+ subject { Measurement.parse('4014489600 in²') }
128
+
129
+ it 'converts to square miles' do
130
+ subject.convert_to(:mi2).quantity.should eq 1
131
+ end
132
+
133
+ it 'converts to square furlongs' do
134
+ subject.convert_to(:fur2).quantity.should eq 64
135
+ end
136
+
137
+ it 'converts to square chains' do
138
+ subject.convert_to(:ch2).quantity.should eq 6_400
139
+ end
140
+
141
+ it 'converts to square yards' do
142
+ subject.convert_to(:yd2).quantity.should eq 3_097_600
143
+ end
144
+
145
+ it 'converts to square feet' do
146
+ subject.convert_to(:ft2).quantity.should eq 27_878_400
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,69 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Measurement do
6
+ describe 'acre-feet' do
7
+ subject { Measurement.parse('1 acre ft') }
8
+
9
+ it 'converts to cubic yards' do
10
+ subject.convert_to(:yd3).quantity.should eq Rational(4840, 3).to_f
11
+ end
12
+
13
+ it 'converts to cubic feet' do
14
+ subject.convert_to(:ft3).quantity.should eq 43_560
15
+ end
16
+
17
+ it 'converts to cubic inches' do
18
+ subject.convert_to(:in3).quantity.should eq 75_271_680
19
+ end
20
+ end
21
+
22
+ describe 'cubic yards' do
23
+ subject { Measurement.parse('1613 1/3 yd³') }
24
+
25
+ it 'converts to acre-feet' do
26
+ subject.convert_to(:'acre ft').quantity.should eq 1
27
+ end
28
+
29
+ it 'converts to cubic feet' do
30
+ subject.convert_to(:ft3).quantity.should eq 43_560
31
+ end
32
+
33
+ it 'converts to cubic inches' do
34
+ subject.convert_to(:in3).quantity.should eq 75_271_680
35
+ end
36
+ end
37
+
38
+ describe 'cubic feet' do
39
+ subject { Measurement.parse('43560 ft³') }
40
+
41
+ it 'converts to acre-feet' do
42
+ subject.convert_to(:'acre ft').quantity.should eq 1
43
+ end
44
+
45
+ it 'converts to cubic yards' do
46
+ subject.convert_to(:yd3).quantity.should eq Rational(4840, 3).to_f
47
+ end
48
+
49
+ it 'converts to cubic inches' do
50
+ subject.convert_to(:in3).quantity.should eq 75_271_680
51
+ end
52
+ end
53
+
54
+ describe 'cubic inches' do
55
+ subject { Measurement.parse('75271680 in³') }
56
+
57
+ it 'converts to acre-feet' do
58
+ subject.convert_to(:'acre ft').quantity.should eq 1
59
+ end
60
+
61
+ it 'converts to cubic yards' do
62
+ subject.convert_to(:yd3).quantity.should eq Rational(4840, 3).to_f
63
+ end
64
+
65
+ it 'converts to cubic feet' do
66
+ subject.convert_to(:ft3).quantity.should eq 43_560
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,261 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Measurement do
6
+ describe 'miles' do
7
+ subject { Measurement.parse('1 mi') }
8
+
9
+ it 'converts to furlongs' do
10
+ subject.convert_to(:fur).quantity.should eq 8
11
+ end
12
+
13
+ it 'converts to chains' do
14
+ subject.convert_to(:ch).quantity.should eq 80
15
+ end
16
+
17
+ it 'converts to fathoms' do
18
+ subject.convert_to(:ftm).quantity.should eq 880
19
+ end
20
+
21
+ it 'converts to yards' do
22
+ subject.convert_to(:yd).quantity.should eq 1_760
23
+ end
24
+
25
+ it 'converts to feet' do
26
+ subject.convert_to(:ft).quantity.should eq 5_280
27
+ end
28
+
29
+ it 'converts to inches' do
30
+ subject.convert_to(:in).quantity.should eq 63_360
31
+ end
32
+
33
+ it 'converts to thou' do
34
+ subject.convert_to(:th).quantity.should eq 63_360_000
35
+ end
36
+ end
37
+
38
+ describe 'furlongs' do
39
+ subject { Measurement.parse('8 fur') }
40
+
41
+ it 'converts to miles' do
42
+ subject.convert_to(:mi).quantity.should eq 1
43
+ end
44
+
45
+ it 'converts to chains' do
46
+ subject.convert_to(:ch).quantity.should eq 80
47
+ end
48
+
49
+ it 'converts to fathoms' do
50
+ subject.convert_to(:ftm).quantity.should eq 880
51
+ end
52
+
53
+ it 'converts to yards' do
54
+ subject.convert_to(:yd).quantity.should eq 1_760
55
+ end
56
+
57
+ it 'converts to feet' do
58
+ subject.convert_to(:ft).quantity.should eq 5_280
59
+ end
60
+
61
+ it 'converts to inches' do
62
+ subject.convert_to(:in).quantity.should eq 63_360
63
+ end
64
+
65
+ it 'converts to thou' do
66
+ subject.convert_to(:th).quantity.should eq 63_360_000
67
+ end
68
+ end
69
+
70
+ describe 'chains' do
71
+ subject { Measurement.parse('80 ch') }
72
+
73
+ it 'converts to miles' do
74
+ subject.convert_to(:mi).quantity.should eq 1
75
+ end
76
+
77
+ it 'converts to furlongs' do
78
+ subject.convert_to(:fur).quantity.should eq 8
79
+ end
80
+
81
+ it 'converts to fathoms' do
82
+ subject.convert_to(:ftm).quantity.should eq 880
83
+ end
84
+
85
+ it 'converts to yards' do
86
+ subject.convert_to(:yd).quantity.should eq 1_760
87
+ end
88
+
89
+ it 'converts to feet' do
90
+ subject.convert_to(:ft).quantity.should eq 5_280
91
+ end
92
+
93
+ it 'converts to inches' do
94
+ subject.convert_to(:in).quantity.should eq 63_360
95
+ end
96
+
97
+ it 'converts to thou' do
98
+ subject.convert_to(:th).quantity.should eq 63_360_000
99
+ end
100
+ end
101
+
102
+ describe 'fathoms' do
103
+ subject { Measurement.parse('880 ftm') }
104
+
105
+ it 'converts to miles' do
106
+ subject.convert_to(:mi).quantity.should eq 1
107
+ end
108
+
109
+ it 'converts to furlongs' do
110
+ subject.convert_to(:fur).quantity.should eq 8
111
+ end
112
+
113
+ it 'converts to chains' do
114
+ subject.convert_to(:ch).quantity.should eq 80
115
+ end
116
+
117
+ it 'converts to yards' do
118
+ subject.convert_to(:yd).quantity.should eq 1_760
119
+ end
120
+
121
+ it 'converts to feet' do
122
+ subject.convert_to(:ft).quantity.should eq 5_280
123
+ end
124
+
125
+ it 'converts to inches' do
126
+ subject.convert_to(:in).quantity.should eq 63_360
127
+ end
128
+
129
+ it 'converts to thou' do
130
+ subject.convert_to(:th).quantity.should eq 63_360_000
131
+ end
132
+ end
133
+
134
+ describe 'yards' do
135
+ subject { Measurement.parse('1760 yd') }
136
+
137
+ it 'converts to miles' do
138
+ subject.convert_to(:mi).quantity.should eq 1
139
+ end
140
+
141
+ it 'converts to furlongs' do
142
+ subject.convert_to(:fur).quantity.should eq 8
143
+ end
144
+
145
+ it 'converts to chains' do
146
+ subject.convert_to(:ch).quantity.should eq 80
147
+ end
148
+
149
+ it 'converts to fathoms' do
150
+ subject.convert_to(:ftm).quantity.should eq 880
151
+ end
152
+
153
+ it 'converts to feet' do
154
+ subject.convert_to(:ft).quantity.should eq 5_280
155
+ end
156
+
157
+ it 'converts to inches' do
158
+ subject.convert_to(:in).quantity.should eq 63_360
159
+ end
160
+
161
+ it 'converts to thou' do
162
+ subject.convert_to(:th).quantity.should eq 63_360_000
163
+ end
164
+ end
165
+
166
+ describe 'feet' do
167
+ subject { Measurement.parse('5280 ft') }
168
+
169
+ it 'converts to miles' do
170
+ subject.convert_to(:mi).quantity.should eq 1
171
+ end
172
+
173
+ it 'converts to furlongs' do
174
+ subject.convert_to(:fur).quantity.should eq 8
175
+ end
176
+
177
+ it 'converts to chains' do
178
+ subject.convert_to(:ch).quantity.should eq 80
179
+ end
180
+
181
+ it 'converts to fathoms' do
182
+ subject.convert_to(:ftm).quantity.should eq 880
183
+ end
184
+
185
+ it 'converts to yards' do
186
+ subject.convert_to(:yd).quantity.should eq 1_760
187
+ end
188
+
189
+ it 'converts to inches' do
190
+ subject.convert_to(:in).quantity.should eq 63_360
191
+ end
192
+
193
+ it 'converts to thou' do
194
+ subject.convert_to(:th).quantity.should eq 63_360_000
195
+ end
196
+ end
197
+
198
+ describe 'inches' do
199
+ subject { Measurement.parse('63360 in') }
200
+
201
+ it 'converts to miles' do
202
+ subject.convert_to(:mi).quantity.should eq 1
203
+ end
204
+
205
+ it 'converts to furlongs' do
206
+ subject.convert_to(:fur).quantity.should eq 8
207
+ end
208
+
209
+ it 'converts to chains' do
210
+ subject.convert_to(:ch).quantity.should eq 80
211
+ end
212
+
213
+ it 'converts to fathoms' do
214
+ subject.convert_to(:ftm).quantity.should eq 880
215
+ end
216
+
217
+ it 'converts to yards' do
218
+ subject.convert_to(:yd).quantity.should eq 1_760
219
+ end
220
+
221
+ it 'converts to feet' do
222
+ subject.convert_to(:ft).quantity.should eq 5_280
223
+ end
224
+
225
+ it 'converts to thou' do
226
+ subject.convert_to(:th).quantity.should eq 63_360_000
227
+ end
228
+ end
229
+
230
+ describe 'thou' do
231
+ subject { Measurement.parse('63360000 th') }
232
+
233
+ it 'converts to miles' do
234
+ subject.convert_to(:mi).quantity.should eq 1
235
+ end
236
+
237
+ it 'converts to furlongs' do
238
+ subject.convert_to(:fur).quantity.should eq 8
239
+ end
240
+
241
+ it 'converts to chains' do
242
+ subject.convert_to(:ch).quantity.should eq 80
243
+ end
244
+
245
+ it 'converts to fathoms' do
246
+ subject.convert_to(:ftm).quantity.should eq 880
247
+ end
248
+
249
+ it 'converts to yards' do
250
+ subject.convert_to(:yd).quantity.should eq 1_760
251
+ end
252
+
253
+ it 'converts to feet' do
254
+ subject.convert_to(:ft).quantity.should eq 5_280
255
+ end
256
+
257
+ it 'converts to inches' do
258
+ subject.convert_to(:in).quantity.should eq 63_360
259
+ end
260
+ end
261
+ end