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,261 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Measurement do
6
+ describe 'kiloliters' do
7
+ subject { Measurement.parse('1 kl') }
8
+
9
+ it 'converts to hectoliters' do
10
+ subject.convert_to(:hl).quantity.should eq 10
11
+ end
12
+
13
+ it 'converts to dekaliters' do
14
+ subject.convert_to(:dal).quantity.should eq 100
15
+ end
16
+
17
+ it 'converts to liters' do
18
+ subject.convert_to(:l).quantity.should eq 1_000
19
+ end
20
+
21
+ it 'converts to deciliters' do
22
+ subject.convert_to(:dl).quantity.should eq 10_000
23
+ end
24
+
25
+ it 'converts to centiliters' do
26
+ subject.convert_to(:cl).quantity.should eq 100_000
27
+ end
28
+
29
+ it 'converts to milliliters' do
30
+ subject.convert_to(:ml).quantity.should eq 1_000_000
31
+ end
32
+
33
+ it 'converts to microliters' do
34
+ subject.convert_to(:µl).quantity.should eq 10_000_000
35
+ end
36
+ end
37
+
38
+ describe 'hectoliters' do
39
+ subject { Measurement.parse('10 hl') }
40
+
41
+ it 'converts to kiloliters' do
42
+ subject.convert_to(:kl).quantity.should eq 1
43
+ end
44
+
45
+ it 'converts to dekaliters' do
46
+ subject.convert_to(:dal).quantity.should eq 100
47
+ end
48
+
49
+ it 'converts to liters' do
50
+ subject.convert_to(:l).quantity.should eq 1_000
51
+ end
52
+
53
+ it 'converts to deciliters' do
54
+ subject.convert_to(:dl).quantity.should eq 10_000
55
+ end
56
+
57
+ it 'converts to centiliters' do
58
+ subject.convert_to(:cl).quantity.should eq 100_000
59
+ end
60
+
61
+ it 'converts to milliliters' do
62
+ subject.convert_to(:ml).quantity.should eq 1_000_000
63
+ end
64
+
65
+ it 'converts to microliters' do
66
+ subject.convert_to(:µl).quantity.should eq 10_000_000
67
+ end
68
+ end
69
+
70
+ describe 'dekaliters' do
71
+ subject { Measurement.parse('100 dal') }
72
+
73
+ it 'converts to kiloliters' do
74
+ subject.convert_to(:kl).quantity.should eq 1
75
+ end
76
+
77
+ it 'converts to hectoliters' do
78
+ subject.convert_to(:hl).quantity.should eq 10
79
+ end
80
+
81
+ it 'converts to liters' do
82
+ subject.convert_to(:l).quantity.should eq 1_000
83
+ end
84
+
85
+ it 'converts to deciliters' do
86
+ subject.convert_to(:dl).quantity.should eq 10_000
87
+ end
88
+
89
+ it 'converts to centiliters' do
90
+ subject.convert_to(:cl).quantity.should eq 100_000
91
+ end
92
+
93
+ it 'converts to milliliters' do
94
+ subject.convert_to(:ml).quantity.should eq 1_000_000
95
+ end
96
+
97
+ it 'converts to microliters' do
98
+ subject.convert_to(:µl).quantity.should eq 10_000_000
99
+ end
100
+ end
101
+
102
+ describe 'liters' do
103
+ subject { Measurement.parse('1000 l') }
104
+
105
+ it 'converts to kiloliters' do
106
+ subject.convert_to(:kl).quantity.should eq 1
107
+ end
108
+
109
+ it 'converts to hectoliters' do
110
+ subject.convert_to(:hl).quantity.should eq 10
111
+ end
112
+
113
+ it 'converts to dekaliters' do
114
+ subject.convert_to(:dal).quantity.should eq 100
115
+ end
116
+
117
+ it 'converts to deciliters' do
118
+ subject.convert_to(:dl).quantity.should eq 10_000
119
+ end
120
+
121
+ it 'converts to centiliters' do
122
+ subject.convert_to(:cl).quantity.should eq 100_000
123
+ end
124
+
125
+ it 'converts to milliliters' do
126
+ subject.convert_to(:ml).quantity.should eq 1_000_000
127
+ end
128
+
129
+ it 'converts to microliters' do
130
+ subject.convert_to(:µl).quantity.should eq 10_000_000
131
+ end
132
+ end
133
+
134
+ describe 'deciliters' do
135
+ subject { Measurement.parse('10000 dl') }
136
+
137
+ it 'converts to kiloliters' do
138
+ subject.convert_to(:kl).quantity.should eq 1
139
+ end
140
+
141
+ it 'converts to hectoliters' do
142
+ subject.convert_to(:hl).quantity.should eq 10
143
+ end
144
+
145
+ it 'converts to dekaliters' do
146
+ subject.convert_to(:dal).quantity.should eq 100
147
+ end
148
+
149
+ it 'converts to liters' do
150
+ subject.convert_to(:l).quantity.should eq 1_000
151
+ end
152
+
153
+ it 'converts to centiliters' do
154
+ subject.convert_to(:cl).quantity.should eq 100_000
155
+ end
156
+
157
+ it 'converts to milliliters' do
158
+ subject.convert_to(:ml).quantity.should eq 1_000_000
159
+ end
160
+
161
+ it 'converts to microliters' do
162
+ subject.convert_to(:µl).quantity.should eq 10_000_000
163
+ end
164
+ end
165
+
166
+ describe 'centiliters' do
167
+ subject { Measurement.parse('100000 cl') }
168
+
169
+ it 'converts to kiloliters' do
170
+ subject.convert_to(:kl).quantity.should eq 1
171
+ end
172
+
173
+ it 'converts to hectoliters' do
174
+ subject.convert_to(:hl).quantity.should eq 10
175
+ end
176
+
177
+ it 'converts to dekaliters' do
178
+ subject.convert_to(:dal).quantity.should eq 100
179
+ end
180
+
181
+ it 'converts to liters' do
182
+ subject.convert_to(:l).quantity.should eq 1_000
183
+ end
184
+
185
+ it 'converts to deciliters' do
186
+ subject.convert_to(:dl).quantity.should eq 10_000
187
+ end
188
+
189
+ it 'converts to milliliters' do
190
+ subject.convert_to(:ml).quantity.should eq 1_000_000
191
+ end
192
+
193
+ it 'converts to microliters' do
194
+ subject.convert_to(:µl).quantity.should eq 10_000_000
195
+ end
196
+ end
197
+
198
+ describe 'milliliters' do
199
+ subject { Measurement.parse('1000000 ml') }
200
+
201
+ it 'converts to kiloliters' do
202
+ subject.convert_to(:kl).quantity.should eq 1
203
+ end
204
+
205
+ it 'converts to hectoliters' do
206
+ subject.convert_to(:hl).quantity.should eq 10
207
+ end
208
+
209
+ it 'converts to dekaliters' do
210
+ subject.convert_to(:dal).quantity.should eq 100
211
+ end
212
+
213
+ it 'converts to liters' do
214
+ subject.convert_to(:l).quantity.should eq 1_000
215
+ end
216
+
217
+ it 'converts to deciliters' do
218
+ subject.convert_to(:dl).quantity.should eq 10_000
219
+ end
220
+
221
+ it 'converts to centiliters' do
222
+ subject.convert_to(:cl).quantity.should eq 100_000
223
+ end
224
+
225
+ it 'converts to microliters' do
226
+ subject.convert_to(:µl).quantity.should eq 10_000_000
227
+ end
228
+ end
229
+
230
+ describe 'microliters' do
231
+ subject { Measurement.parse('10000000 µl') }
232
+
233
+ it 'converts to kiloliters' do
234
+ subject.convert_to(:kl).quantity.should eq 1
235
+ end
236
+
237
+ it 'converts to hectoliters' do
238
+ subject.convert_to(:hl).quantity.should eq 10
239
+ end
240
+
241
+ it 'converts to dekaliters' do
242
+ subject.convert_to(:dal).quantity.should eq 100
243
+ end
244
+
245
+ it 'converts to liters' do
246
+ subject.convert_to(:l).quantity.should eq 1_000
247
+ end
248
+
249
+ it 'converts to deciliters' do
250
+ subject.convert_to(:dl).quantity.should eq 10_000
251
+ end
252
+
253
+ it 'converts to centiliters' do
254
+ subject.convert_to(:cl).quantity.should eq 100_000
255
+ end
256
+
257
+ it 'converts to milliliters' do
258
+ subject.convert_to(:ml).quantity.should eq 1_000_000
259
+ end
260
+ end
261
+ end
@@ -0,0 +1,325 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Measurement do
6
+ describe 'tonnes' do
7
+ subject { Measurement.parse('0.001 tonne') }
8
+
9
+ it 'converts to hectograms' do
10
+ subject.convert_to(:hg).quantity.should eq 10
11
+ end
12
+
13
+ it 'converts to dekagrams' do
14
+ subject.convert_to(:dag).quantity.should eq 100
15
+ end
16
+
17
+ it 'converts to grams' do
18
+ subject.convert_to(:g).quantity.should eq 1_000
19
+ end
20
+
21
+ it 'converts to decigrams' do
22
+ subject.convert_to(:dg).quantity.should eq 10_000
23
+ end
24
+
25
+ it 'converts to centigrams' do
26
+ subject.convert_to(:cg).quantity.should eq 100_000
27
+ end
28
+
29
+ it 'converts to milligrams' do
30
+ subject.convert_to(:mg).quantity.should eq 1_000_000
31
+ end
32
+
33
+ it 'converts to micrograms' do
34
+ subject.convert_to(:µg).quantity.should eq 10_000_000
35
+ end
36
+ end
37
+
38
+ describe 'kilograms' do
39
+ subject { Measurement.parse('1 kg') }
40
+
41
+ it 'converts to tonnes' do
42
+ subject.convert_to(:t).quantity.should eq 0.001
43
+ end
44
+
45
+ it 'converts to hectograms' do
46
+ subject.convert_to(:hg).quantity.should eq 10
47
+ end
48
+
49
+ it 'converts to dekagrams' do
50
+ subject.convert_to(:dag).quantity.should eq 100
51
+ end
52
+
53
+ it 'converts to grams' do
54
+ subject.convert_to(:g).quantity.should eq 1_000
55
+ end
56
+
57
+ it 'converts to decigrams' do
58
+ subject.convert_to(:dg).quantity.should eq 10_000
59
+ end
60
+
61
+ it 'converts to centigrams' do
62
+ subject.convert_to(:cg).quantity.should eq 100_000
63
+ end
64
+
65
+ it 'converts to milligrams' do
66
+ subject.convert_to(:mg).quantity.should eq 1_000_000
67
+ end
68
+
69
+ it 'converts to micrograms' do
70
+ subject.convert_to(:µg).quantity.should eq 10_000_000
71
+ end
72
+ end
73
+
74
+ describe 'hectograms' do
75
+ subject { Measurement.parse('10 hg') }
76
+
77
+ it 'converts to tonnes' do
78
+ subject.convert_to(:t).quantity.should eq 0.001
79
+ end
80
+
81
+ it 'converts to kilograms' do
82
+ subject.convert_to(:kg).quantity.should eq 1
83
+ end
84
+
85
+ it 'converts to dekagrams' do
86
+ subject.convert_to(:dag).quantity.should eq 100
87
+ end
88
+
89
+ it 'converts to grams' do
90
+ subject.convert_to(:g).quantity.should eq 1_000
91
+ end
92
+
93
+ it 'converts to decigrams' do
94
+ subject.convert_to(:dg).quantity.should eq 10_000
95
+ end
96
+
97
+ it 'converts to centigrams' do
98
+ subject.convert_to(:cg).quantity.should eq 100_000
99
+ end
100
+
101
+ it 'converts to milligrams' do
102
+ subject.convert_to(:mg).quantity.should eq 1_000_000
103
+ end
104
+
105
+ it 'converts to micrograms' do
106
+ subject.convert_to(:µg).quantity.should eq 10_000_000
107
+ end
108
+ end
109
+
110
+ describe 'dekagrams' do
111
+ subject { Measurement.parse('100 dag') }
112
+
113
+ it 'converts to tonnes' do
114
+ subject.convert_to(:t).quantity.should eq 0.001
115
+ end
116
+
117
+ it 'converts to kilograms' do
118
+ subject.convert_to(:kg).quantity.should eq 1
119
+ end
120
+
121
+ it 'converts to hectograms' do
122
+ subject.convert_to(:hg).quantity.should eq 10
123
+ end
124
+
125
+ it 'converts to grams' do
126
+ subject.convert_to(:g).quantity.should eq 1_000
127
+ end
128
+
129
+ it 'converts to decigrams' do
130
+ subject.convert_to(:dg).quantity.should eq 10_000
131
+ end
132
+
133
+ it 'converts to centigrams' do
134
+ subject.convert_to(:cg).quantity.should eq 100_000
135
+ end
136
+
137
+ it 'converts to milligrams' do
138
+ subject.convert_to(:mg).quantity.should eq 1_000_000
139
+ end
140
+
141
+ it 'converts to micrograms' do
142
+ subject.convert_to(:µg).quantity.should eq 10_000_000
143
+ end
144
+ end
145
+
146
+ describe 'grams' do
147
+ subject { Measurement.parse('1000 g') }
148
+
149
+ it 'converts to tonnes' do
150
+ subject.convert_to(:t).quantity.should eq 0.001
151
+ end
152
+
153
+ it 'converts to kilograms' do
154
+ subject.convert_to(:kg).quantity.should eq 1
155
+ end
156
+
157
+ it 'converts to hectograms' do
158
+ subject.convert_to(:hg).quantity.should eq 10
159
+ end
160
+
161
+ it 'converts to dekagrams' do
162
+ subject.convert_to(:dag).quantity.should eq 100
163
+ end
164
+
165
+ it 'converts to decigrams' do
166
+ subject.convert_to(:dg).quantity.should eq 10_000
167
+ end
168
+
169
+ it 'converts to centigrams' do
170
+ subject.convert_to(:cg).quantity.should eq 100_000
171
+ end
172
+
173
+ it 'converts to milligrams' do
174
+ subject.convert_to(:mg).quantity.should eq 1_000_000
175
+ end
176
+
177
+ it 'converts to micrograms' do
178
+ subject.convert_to(:µg).quantity.should eq 10_000_000
179
+ end
180
+ end
181
+
182
+ describe 'decigrams' do
183
+ subject { Measurement.parse('10000 dg') }
184
+
185
+ it 'converts to tonnes' do
186
+ subject.convert_to(:t).quantity.should eq 0.001
187
+ end
188
+
189
+ it 'converts to kilograms' do
190
+ subject.convert_to(:kg).quantity.should eq 1
191
+ end
192
+
193
+ it 'converts to hectograms' do
194
+ subject.convert_to(:hg).quantity.should eq 10
195
+ end
196
+
197
+ it 'converts to dekagrams' do
198
+ subject.convert_to(:dag).quantity.should eq 100
199
+ end
200
+
201
+ it 'converts to grams' do
202
+ subject.convert_to(:g).quantity.should eq 1_000
203
+ end
204
+
205
+ it 'converts to centigrams' do
206
+ subject.convert_to(:cg).quantity.should eq 100_000
207
+ end
208
+
209
+ it 'converts to milligrams' do
210
+ subject.convert_to(:mg).quantity.should eq 1_000_000
211
+ end
212
+
213
+ it 'converts to micrograms' do
214
+ subject.convert_to(:µg).quantity.should eq 10_000_000
215
+ end
216
+ end
217
+
218
+ describe 'centigrams' do
219
+ subject { Measurement.parse('100000 cg') }
220
+
221
+ it 'converts to tonnes' do
222
+ subject.convert_to(:t).quantity.should eq 0.001
223
+ end
224
+
225
+ it 'converts to kilograms' do
226
+ subject.convert_to(:kg).quantity.should eq 1
227
+ end
228
+
229
+ it 'converts to hectograms' do
230
+ subject.convert_to(:hg).quantity.should eq 10
231
+ end
232
+
233
+ it 'converts to dekagrams' do
234
+ subject.convert_to(:dag).quantity.should eq 100
235
+ end
236
+
237
+ it 'converts to grams' do
238
+ subject.convert_to(:g).quantity.should eq 1_000
239
+ end
240
+
241
+ it 'converts to decigrams' do
242
+ subject.convert_to(:dg).quantity.should eq 10_000
243
+ end
244
+
245
+ it 'converts to milligrams' do
246
+ subject.convert_to(:mg).quantity.should eq 1_000_000
247
+ end
248
+
249
+ it 'converts to micrograms' do
250
+ subject.convert_to(:µg).quantity.should eq 10_000_000
251
+ end
252
+ end
253
+
254
+ describe 'milligrams' do
255
+ subject { Measurement.parse('1000000 mg') }
256
+
257
+ it 'converts to tonnes' do
258
+ subject.convert_to(:t).quantity.should eq 0.001
259
+ end
260
+
261
+ it 'converts to kilograms' do
262
+ subject.convert_to(:kg).quantity.should eq 1
263
+ end
264
+
265
+ it 'converts to hectograms' do
266
+ subject.convert_to(:hg).quantity.should eq 10
267
+ end
268
+
269
+ it 'converts to dekagrams' do
270
+ subject.convert_to(:dag).quantity.should eq 100
271
+ end
272
+
273
+ it 'converts to grams' do
274
+ subject.convert_to(:g).quantity.should eq 1_000
275
+ end
276
+
277
+ it 'converts to decigrams' do
278
+ subject.convert_to(:dg).quantity.should eq 10_000
279
+ end
280
+
281
+ it 'converts to centigrams' do
282
+ subject.convert_to(:cg).quantity.should eq 100_000
283
+ end
284
+
285
+ it 'converts to micrograms' do
286
+ subject.convert_to(:µg).quantity.should eq 10_000_000
287
+ end
288
+ end
289
+
290
+ describe 'micrograms' do
291
+ subject { Measurement.parse('10000000 µg') }
292
+
293
+ it 'converts to tonnes' do
294
+ subject.convert_to(:t).quantity.should eq 0.001
295
+ end
296
+
297
+ it 'converts to kilograms' do
298
+ subject.convert_to(:kg).quantity.should eq 1
299
+ end
300
+
301
+ it 'converts to hectograms' do
302
+ subject.convert_to(:hg).quantity.should eq 10
303
+ end
304
+
305
+ it 'converts to dekagrams' do
306
+ subject.convert_to(:dag).quantity.should eq 100
307
+ end
308
+
309
+ it 'converts to grams' do
310
+ subject.convert_to(:g).quantity.should eq 1_000
311
+ end
312
+
313
+ it 'converts to decigrams' do
314
+ subject.convert_to(:dg).quantity.should eq 10_000
315
+ end
316
+
317
+ it 'converts to centigrams' do
318
+ subject.convert_to(:cg).quantity.should eq 100_000
319
+ end
320
+
321
+ it 'converts to milligrams' do
322
+ subject.convert_to(:mg).quantity.should eq 1_000_000
323
+ end
324
+ end
325
+ end