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