unit_measurements 2.6.0 → 2.6.1
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/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/README.md +62 -62
- data/lib/unit_measurements/arithmetic.rb +4 -4
- data/lib/unit_measurements/conversion.rb +5 -5
- data/lib/unit_measurements/formatter.rb +2 -2
- data/lib/unit_measurements/math.rb +4 -4
- data/lib/unit_measurements/unit_groups/amount_of_substance.rb +2 -2
- data/lib/unit_measurements/unit_groups/area.rb +6 -6
- data/lib/unit_measurements/unit_groups/density.rb +5 -5
- data/lib/unit_measurements/unit_groups/electric_current.rb +4 -4
- data/lib/unit_measurements/unit_groups/force.rb +7 -7
- data/lib/unit_measurements/unit_groups/length.rb +5 -5
- data/lib/unit_measurements/unit_groups/luminous_intensity.rb +2 -2
- data/lib/unit_measurements/unit_groups/plane_angle.rb +9 -9
- data/lib/unit_measurements/unit_groups/quantity.rb +5 -5
- data/lib/unit_measurements/unit_groups/solid_angle.rb +5 -5
- data/lib/unit_measurements/unit_groups/sound_level.rb +2 -2
- data/lib/unit_measurements/unit_groups/temperature.rb +2 -2
- data/lib/unit_measurements/unit_groups/time.rb +11 -11
- data/lib/unit_measurements/unit_groups/volume.rb +10 -10
- data/lib/unit_measurements/unit_groups/weight.rb +3 -3
- data/lib/unit_measurements/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee248c59c5e2a882f8d4777e9e33e45c7adcd595a407720b65f36c0c9d0dc420
|
4
|
+
data.tar.gz: ad7e62f717a032d15d1cd41faead043090d16fd648f239566184a73b413ba6d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c1b028748ae14888b1041dfbe640f00bbd42d4e5498d63298298bbff52c5cc8ccb0eb568ba994dd2a5a43fa843bc4cf5c9ff282ce33b6a2b2167ee7693fc98e
|
7
|
+
data.tar.gz: 3e4685f5ea0665b95931580a5a321bdadb28374c90ccb35b57dff74e635cf5f8b6596dbeff3a924a4ef122e82dd1687e3fbc952325f2465667c92296a4413672
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## [2.6.1](https://github.com/shivam091/unit_measurements/compare/v2.6.0...v2.6.1) - 2023-08-24
|
2
|
+
|
3
|
+
### What's changed
|
4
|
+
|
5
|
+
- Replaced `Symbol` by `String` in unit names and symbols.
|
6
|
+
|
7
|
+
----------
|
8
|
+
|
1
9
|
## [2.6.0](https://github.com/shivam091/unit_measurements/compare/v2.5.0...v2.6.0) - 2023-08-24
|
2
10
|
|
3
11
|
### What's new
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -65,7 +65,7 @@ but rather with the unit group classes viz., `UnitMeasurements::Weight`, `UnitMe
|
|
65
65
|
**Initialize a measurement:**
|
66
66
|
|
67
67
|
```ruby
|
68
|
-
UnitMeasurements::Weight.new(1,
|
68
|
+
UnitMeasurements::Weight.new(1, "kg")
|
69
69
|
#=> 1 kg
|
70
70
|
```
|
71
71
|
|
@@ -78,21 +78,21 @@ or `#convert_to!` (aliased as `#to!`) methods.
|
|
78
78
|
You can use `#convert_to` as:
|
79
79
|
|
80
80
|
```ruby
|
81
|
-
UnitMeasurements::Weight.new(1,
|
81
|
+
UnitMeasurements::Weight.new(1, "kg").convert_to("g")
|
82
82
|
#=> 1000.0 g
|
83
83
|
```
|
84
84
|
|
85
85
|
If you want to modify measurement object itself, you can use `#convert_to!` method as:
|
86
86
|
|
87
87
|
```ruby
|
88
|
-
UnitMeasurements::Weight.new(1,
|
88
|
+
UnitMeasurements::Weight.new(1, "kg").convert_to!("g")
|
89
89
|
#=> 1000.0 g
|
90
90
|
```
|
91
91
|
|
92
92
|
You can also chain call of `#convert_to` and `#convert_to!` methods as:
|
93
93
|
|
94
94
|
```ruby
|
95
|
-
UnitMeasurements::Weight.new(1,
|
95
|
+
UnitMeasurements::Weight.new(1, "kg").convert_to("g").convert_to("t").convert_to!("q")
|
96
96
|
#=> 0.01 q
|
97
97
|
```
|
98
98
|
|
@@ -117,11 +117,11 @@ UnitMeasurements::Weight.parse("1 kg in g")
|
|
117
117
|
**Parse rational numbers, source unit, and (or) target unit:**
|
118
118
|
|
119
119
|
```ruby
|
120
|
-
UnitMeasurements::Weight.new(Rational(2, 3),
|
120
|
+
UnitMeasurements::Weight.new(Rational(2, 3), "kg").convert_to("g")
|
121
121
|
#=> 666.666666666667 g
|
122
|
-
UnitMeasurements::Weight.new("2/3",
|
122
|
+
UnitMeasurements::Weight.new("2/3", "kg").convert_to("g")
|
123
123
|
#=> 666.666666666667 g
|
124
|
-
UnitMeasurements::Weight.parse("2/3 kg").convert_to(
|
124
|
+
UnitMeasurements::Weight.parse("2/3 kg").convert_to("g")
|
125
125
|
#=> 666.666666666667 g
|
126
126
|
UnitMeasurements::Weight.parse("2/3 kg to g")
|
127
127
|
#=> 666.666666666667 g
|
@@ -130,11 +130,11 @@ UnitMeasurements::Weight.parse("2/3 kg to g")
|
|
130
130
|
**Parse complex numbers, source unit, and (or) target unit:**
|
131
131
|
|
132
132
|
```ruby
|
133
|
-
UnitMeasurements::Weight.new(Complex(2, 3),
|
133
|
+
UnitMeasurements::Weight.new(Complex(2, 3), "kg").convert_to("g")
|
134
134
|
#=> 2000.0+3000.0i g
|
135
|
-
UnitMeasurements::Weight.new("2+3i",
|
135
|
+
UnitMeasurements::Weight.new("2+3i", "kg").convert_to("g")
|
136
136
|
#=> 2000.0+3000.0i g
|
137
|
-
UnitMeasurements::Weight.parse("2+3i kg").convert_to(
|
137
|
+
UnitMeasurements::Weight.parse("2+3i kg").convert_to("g")
|
138
138
|
#=> 2000.0+3000.0i g
|
139
139
|
UnitMeasurements::Weight.parse("2+3i kg to g")
|
140
140
|
#=> 2000.0+3000.0i g
|
@@ -143,11 +143,11 @@ UnitMeasurements::Weight.parse("2+3i kg to g")
|
|
143
143
|
**Parse scientific numbers, source unit, and (or) target unit:**
|
144
144
|
|
145
145
|
```ruby
|
146
|
-
UnitMeasurements::Weight.new(BigDecimal(2),
|
146
|
+
UnitMeasurements::Weight.new(BigDecimal(2), "kg").convert_to("g")
|
147
147
|
#=> 2000.0 g
|
148
|
-
UnitMeasurements::Weight.new(0.2e1,
|
148
|
+
UnitMeasurements::Weight.new(0.2e1, "kg").convert_to("g")
|
149
149
|
#=> 2000.0 g
|
150
|
-
UnitMeasurements::Weight.parse("0.2e1 kg").convert_to(
|
150
|
+
UnitMeasurements::Weight.parse("0.2e1 kg").convert_to("g")
|
151
151
|
#=> 2000.0 g
|
152
152
|
UnitMeasurements::Weight.parse("0.2e1 kg to g")
|
153
153
|
#=> 2000.0 g
|
@@ -156,9 +156,9 @@ UnitMeasurements::Weight.parse("0.2e1 kg to g")
|
|
156
156
|
**Parse ratios, source unit, and (or) target unit:**
|
157
157
|
|
158
158
|
```ruby
|
159
|
-
UnitMeasurements::Weight.new("1:2",
|
159
|
+
UnitMeasurements::Weight.new("1:2", "kg").convert_to("g")
|
160
160
|
#=> 500.0 g
|
161
|
-
UnitMeasurements::Weight.parse("1:2 kg").convert_to(
|
161
|
+
UnitMeasurements::Weight.parse("1:2 kg").convert_to("g")
|
162
162
|
#=> 500.0 g
|
163
163
|
UnitMeasurements::Weight.parse("1:2 kg to g")
|
164
164
|
#=> 500.0 g
|
@@ -167,15 +167,15 @@ UnitMeasurements::Weight.parse("1:2 kg to g")
|
|
167
167
|
**Parse fractional notations, source unit, and (or) target unit:**
|
168
168
|
|
169
169
|
```ruby
|
170
|
-
UnitMeasurements::Weight.new("1/2",
|
170
|
+
UnitMeasurements::Weight.new("1/2", "kg").convert_to("g")
|
171
171
|
#=> 500.0 g
|
172
|
-
UnitMeasurements::Weight.parse("1/2 kg").convert_to(
|
172
|
+
UnitMeasurements::Weight.parse("1/2 kg").convert_to("g")
|
173
173
|
#=> 500.0 g
|
174
174
|
UnitMeasurements::Weight.parse("1/2 kg to g")
|
175
175
|
#=> 500.0 g
|
176
|
-
UnitMeasurements::Weight.new("½",
|
176
|
+
UnitMeasurements::Weight.new("½", "kg").convert_to("g")
|
177
177
|
#=> 500.0 g
|
178
|
-
UnitMeasurements::Weight.parse("½ kg").convert_to(
|
178
|
+
UnitMeasurements::Weight.parse("½ kg").convert_to("g")
|
179
179
|
#=> 500.0 g
|
180
180
|
UnitMeasurements::Weight.parse("½ kg to g")
|
181
181
|
#=> 500.0 g
|
@@ -184,15 +184,15 @@ UnitMeasurements::Weight.parse("½ kg to g")
|
|
184
184
|
**Parse mixed fractional notations, source unit, and (or) target unit:**
|
185
185
|
|
186
186
|
```ruby
|
187
|
-
UnitMeasurements::Weight.new("2 1/2",
|
187
|
+
UnitMeasurements::Weight.new("2 1/2", "kg").convert_to("g")
|
188
188
|
#=> 2500.0 g
|
189
|
-
UnitMeasurements::Weight.parse("2 1/2 kg").convert_to(
|
189
|
+
UnitMeasurements::Weight.parse("2 1/2 kg").convert_to("g")
|
190
190
|
#=> 2500.0 g
|
191
191
|
UnitMeasurements::Weight.parse("2 1/2 kg to g")
|
192
192
|
#=> 2500.0 g
|
193
|
-
UnitMeasurements::Weight.new("2 ½",
|
193
|
+
UnitMeasurements::Weight.new("2 ½", "kg").convert_to("g")
|
194
194
|
#=> 2500.0 g
|
195
|
-
UnitMeasurements::Weight.parse("2 ½ kg").convert_to(
|
195
|
+
UnitMeasurements::Weight.parse("2 ½ kg").convert_to("g")
|
196
196
|
#=> 2500.0 g
|
197
197
|
UnitMeasurements::Weight.parse("2 ½ kg to g")
|
198
198
|
#=> 2500.0 g
|
@@ -203,15 +203,15 @@ Supported special characters for fractional notations are `¼`, `½`, `¾`, `⅓
|
|
203
203
|
**Parse exponents, source unit, and (or) target unit:**
|
204
204
|
|
205
205
|
```ruby
|
206
|
-
UnitMeasurements::Weight.new("2e+2",
|
206
|
+
UnitMeasurements::Weight.new("2e+2", "kg").convert_to("g")
|
207
207
|
#=> 200000.0 g
|
208
|
-
UnitMeasurements::Weight.parse("2e² kg").convert_to(
|
208
|
+
UnitMeasurements::Weight.parse("2e² kg").convert_to("g")
|
209
209
|
#=> 200000.0 g
|
210
210
|
UnitMeasurements::Weight.parse("2e+2 kg to g")
|
211
211
|
#=> 200000.0 g
|
212
|
-
UnitMeasurements::Weight.new("2e⁺²",
|
212
|
+
UnitMeasurements::Weight.new("2e⁺²", "kg").convert_to("g")
|
213
213
|
#=> 200000.0 g
|
214
|
-
UnitMeasurements::Weight.parse("2e⁺2 kg").convert_to(
|
214
|
+
UnitMeasurements::Weight.parse("2e⁺2 kg").convert_to("g")
|
215
215
|
#=> 200000.0 g
|
216
216
|
UnitMeasurements::Weight.parse("2e⁻² kg to g")
|
217
217
|
#=> 20.0 g
|
@@ -225,18 +225,18 @@ If you want to format measurement to certain format, you can use `#format` metho
|
|
225
225
|
If format is not specified, it defaults to `"%.2<value>f %<unit>s"`.
|
226
226
|
|
227
227
|
```ruby
|
228
|
-
UnitMeasurements::Weight.parse("2 kg").to(
|
228
|
+
UnitMeasurements::Weight.parse("2 kg").to("st").format
|
229
229
|
#=> "0.31 st"
|
230
|
-
UnitMeasurements::Weight.parse("2 kg").to(
|
230
|
+
UnitMeasurements::Weight.parse("2 kg").to("st").format("%.4<quantity>f %<unit>s")
|
231
231
|
#=> "0.3149 st"
|
232
|
-
UnitMeasurements::Weight.parse("2 kg").to(
|
232
|
+
UnitMeasurements::Weight.parse("2 kg").to("st").format("%.4<quantity>f")
|
233
233
|
#=> "0.3149"
|
234
234
|
```
|
235
235
|
|
236
236
|
**Extract the unit and the quantity from measurement:**
|
237
237
|
|
238
238
|
```ruby
|
239
|
-
weight = UnitMeasurements::Weight.new(1,
|
239
|
+
weight = UnitMeasurements::Weight.new(1, "kg")
|
240
240
|
weight.quantity
|
241
241
|
#=> 1
|
242
242
|
weight.unit
|
@@ -271,35 +271,35 @@ the unit group. `#unit_for!` method returns error if a unit is not present in th
|
|
271
271
|
unit group.
|
272
272
|
|
273
273
|
```ruby
|
274
|
-
UnitMeasurements::Weight.unit_for(
|
274
|
+
UnitMeasurements::Weight.unit_for("g")
|
275
275
|
#=> #<UnitMeasurements::Unit: g (gram, gramme, grammes, grams)>
|
276
|
-
UnitMeasurements::Weight.unit_for(
|
276
|
+
UnitMeasurements::Weight.unit_for("z")
|
277
277
|
#=> nil
|
278
|
-
UnitMeasurements::Weight.unit_for!(
|
278
|
+
UnitMeasurements::Weight.unit_for!("g")
|
279
279
|
#=> #<UnitMeasurements::Unit: g (gram, gramme, grammes, grams)>
|
280
|
-
UnitMeasurements::Weight.unit_for!(
|
280
|
+
UnitMeasurements::Weight.unit_for!("z")
|
281
281
|
#=> Invalid unit: 'z'. (UnitMeasurements::UnitError)
|
282
282
|
```
|
283
283
|
|
284
284
|
**Finding whether the unit is defined within the unit group:**
|
285
285
|
|
286
286
|
```ruby
|
287
|
-
UnitMeasurements::Weight.defined?(
|
287
|
+
UnitMeasurements::Weight.defined?("g")
|
288
288
|
#=> true
|
289
|
-
UnitMeasurements::Weight.defined?(
|
289
|
+
UnitMeasurements::Weight.defined?("kg")
|
290
290
|
#=> true
|
291
|
-
UnitMeasurements::Weight.defined?(
|
291
|
+
UnitMeasurements::Weight.defined?("gramme")
|
292
292
|
#=> false
|
293
293
|
```
|
294
294
|
|
295
295
|
**Check if the unit is a valid unit or alias within the unit group:**
|
296
296
|
|
297
297
|
```ruby
|
298
|
-
UnitMeasurements::Weight.unit_or_alias?(
|
298
|
+
UnitMeasurements::Weight.unit_or_alias?("g")
|
299
299
|
#=> true
|
300
|
-
UnitMeasurements::Weight.unit_or_alias?(
|
300
|
+
UnitMeasurements::Weight.unit_or_alias?("kg")
|
301
301
|
#=> true
|
302
|
-
UnitMeasurements::Weight.unit_or_alias?(
|
302
|
+
UnitMeasurements::Weight.unit_or_alias?("gramme")
|
303
303
|
#=> true
|
304
304
|
```
|
305
305
|
|
@@ -319,9 +319,9 @@ UnitMeasurements::Weight.parse("1 kg") <= UnitMeasurements::Weight.parse("0.5 kg
|
|
319
319
|
#=> false
|
320
320
|
UnitMeasurements::Weight.parse("1 kg") >= UnitMeasurements::Weight.parse("0.5 kg")
|
321
321
|
#=> true
|
322
|
-
UnitMeasurements::Length.new(1,
|
322
|
+
UnitMeasurements::Length.new(1, "ft").between?(UnitMeasurements::Length.new(12, "in"), UnitMeasurements::Length.new(24, "in"))
|
323
323
|
#=> true
|
324
|
-
UnitMeasurements::Length.new(1,
|
324
|
+
UnitMeasurements::Length.new(1, "ft").clamp(UnitMeasurements::Length.new(13, "in"), UnitMeasurements::Length.new(24, "in"))
|
325
325
|
#=> 13 in
|
326
326
|
```
|
327
327
|
|
@@ -338,13 +338,13 @@ measurement by either other compatible measurement or number.
|
|
338
338
|
4. `#/` - Divides the measurement quantity by other measurement quantity or number.
|
339
339
|
|
340
340
|
```ruby
|
341
|
-
UnitMeasurements::Weight.new(1,
|
341
|
+
UnitMeasurements::Weight.new(1, "kg") + UnitMeasurements::Weight.new(1, "g")
|
342
342
|
#=> 1.001 kg
|
343
|
-
UnitMeasurements::Weight.new(2,
|
343
|
+
UnitMeasurements::Weight.new(2, "kg") - 1
|
344
344
|
#=> 1 kg
|
345
|
-
UnitMeasurements::Weight.new(2,
|
345
|
+
UnitMeasurements::Weight.new(2, "kg") * 2
|
346
346
|
#=> 4 kg
|
347
|
-
UnitMeasurements::Weight.new(4,
|
347
|
+
UnitMeasurements::Weight.new(4, "kg") / UnitMeasurements::Weight.new(2, "kg")
|
348
348
|
#=> 2 kg
|
349
349
|
```
|
350
350
|
|
@@ -359,13 +359,13 @@ You can perform mathematical operations on the measurements.
|
|
359
359
|
4. `#ceil` - Rounds quantity of the measurement to next higher integer.
|
360
360
|
|
361
361
|
```ruby
|
362
|
-
UnitMeasurements::Weight.new(1,
|
362
|
+
UnitMeasurements::Weight.new(1, "g").convert_to("st").round(4)
|
363
363
|
#=> 0.0002 st
|
364
|
-
UnitMeasurements::Length.new(-17.625,
|
364
|
+
UnitMeasurements::Length.new(-17.625, "m").abs
|
365
365
|
#=> 17.625 m
|
366
|
-
UnitMeasurements::Length.new(17.625,
|
366
|
+
UnitMeasurements::Length.new(17.625, "m").floor
|
367
367
|
#=> 17 m
|
368
|
-
UnitMeasurements::Length.new(17.625,
|
368
|
+
UnitMeasurements::Length.new(17.625, "m").ceil
|
369
369
|
#=> 18 m
|
370
370
|
```
|
371
371
|
|
@@ -375,15 +375,15 @@ You can convert measurement quantity directly to other numeric types viz.
|
|
375
375
|
`Integer`, `BigDecimal`, `Rational`, `Complex`, and `Float`.
|
376
376
|
|
377
377
|
```ruby
|
378
|
-
UnitMeasurements::Weight.new(2.25567,
|
378
|
+
UnitMeasurements::Weight.new(2.25567, "kg").to_i
|
379
379
|
#=> 2 kg
|
380
|
-
UnitMeasurements::Weight.new(2.25567,
|
380
|
+
UnitMeasurements::Weight.new(2.25567, "kg").to_f
|
381
381
|
#=> 2.25567 kg
|
382
|
-
UnitMeasurements::Weight.new(2.25567,
|
382
|
+
UnitMeasurements::Weight.new(2.25567, "kg").to_r
|
383
383
|
#=> 225567/100000 kg
|
384
|
-
UnitMeasurements::Weight.new(2.25567,
|
384
|
+
UnitMeasurements::Weight.new(2.25567, "kg").to_d
|
385
385
|
#=> 2.25567 kg
|
386
|
-
UnitMeasurements::Weight.new(2.25567,
|
386
|
+
UnitMeasurements::Weight.new(2.25567, "kg").to_c
|
387
387
|
#=> 2.25567+0i kg
|
388
388
|
```
|
389
389
|
|
@@ -474,18 +474,18 @@ If you build unit using `base` method, base unit automatically gets set for the
|
|
474
474
|
```ruby
|
475
475
|
UnitMeasurements::Time = UnitMeasurements.build do
|
476
476
|
# Add a base unit to the group.
|
477
|
-
base
|
477
|
+
base "s", aliases: ["second", "seconds"]
|
478
478
|
|
479
479
|
# Add other units to the group, along with their conversion multipliers against
|
480
480
|
# base unit.
|
481
|
-
unit
|
481
|
+
unit "min", value: 60.0, aliases: ["minute", "minutes"]
|
482
482
|
|
483
483
|
# You can also specify conversion string if it's converted against a unit other
|
484
484
|
# than the unit group's base unit.
|
485
|
-
unit
|
485
|
+
unit "h", value: "60 min", aliases: ["hour", "hours"]
|
486
486
|
|
487
487
|
# You can also specify unit value as an array.
|
488
|
-
unit
|
488
|
+
unit "d", value: [24, "h"], aliases: ["day", "days"]
|
489
489
|
end
|
490
490
|
```
|
491
491
|
|
@@ -495,9 +495,9 @@ If you build unit using `si_unit`, Base unit is automatically added to the group
|
|
495
495
|
```ruby
|
496
496
|
UnitMeasurements::Time = UnitMeasurements.build do
|
497
497
|
# Add a SI unit to the unit group
|
498
|
-
si_unit
|
498
|
+
si_unit "s", aliases: ["second", "seconds"]
|
499
499
|
|
500
|
-
unit
|
500
|
+
unit "min", value: "60 s", aliases: ["minute", "minutes"]
|
501
501
|
end
|
502
502
|
```
|
503
503
|
|
@@ -9,7 +9,7 @@ module UnitMeasurements
|
|
9
9
|
# @param [Numeric or Measurement] other
|
10
10
|
#
|
11
11
|
# @example
|
12
|
-
# UnitMeasurements::Weight.new(1,
|
12
|
+
# UnitMeasurements::Weight.new(1, "kg") + UnitMeasurements::Weight.new(1, "g")
|
13
13
|
# => 1.001 kg
|
14
14
|
#
|
15
15
|
# @return [Measurement]
|
@@ -22,7 +22,7 @@ module UnitMeasurements
|
|
22
22
|
# @param [Numeric or Measurement] other
|
23
23
|
#
|
24
24
|
# @example
|
25
|
-
# UnitMeasurements::Weight.new(2,
|
25
|
+
# UnitMeasurements::Weight.new(2, "kg") - 1
|
26
26
|
# => 1 kg
|
27
27
|
#
|
28
28
|
# @return [Measurement]
|
@@ -35,7 +35,7 @@ module UnitMeasurements
|
|
35
35
|
# @param [Numeric or Measurement] other
|
36
36
|
#
|
37
37
|
# @example
|
38
|
-
# UnitMeasurements::Weight.new(2,
|
38
|
+
# UnitMeasurements::Weight.new(2, "kg") * 2
|
39
39
|
# => 4 kg
|
40
40
|
#
|
41
41
|
# @return [Measurement]
|
@@ -48,7 +48,7 @@ module UnitMeasurements
|
|
48
48
|
# @param [Numeric or Measurement] other
|
49
49
|
#
|
50
50
|
# @example
|
51
|
-
# UnitMeasurements::Weight.new(4,
|
51
|
+
# UnitMeasurements::Weight.new(4, "kg") / UnitMeasurements::Weight.new(2, "kg")
|
52
52
|
# => 2 kg
|
53
53
|
#
|
54
54
|
# @return [Measurement]
|
@@ -7,7 +7,7 @@ module UnitMeasurements
|
|
7
7
|
# Converts quantity of the measurement to +Integer+.
|
8
8
|
#
|
9
9
|
# @example
|
10
|
-
# UnitMeasurements::Weight.new(2.25567,
|
10
|
+
# UnitMeasurements::Weight.new(2.25567, "kg").to_i
|
11
11
|
# => 2 kg
|
12
12
|
#
|
13
13
|
# @return [Measurement]
|
@@ -18,7 +18,7 @@ module UnitMeasurements
|
|
18
18
|
# Converts quantity of the measurement to +Float+.
|
19
19
|
#
|
20
20
|
# @example
|
21
|
-
# UnitMeasurements::Weight.new(2.25567,
|
21
|
+
# UnitMeasurements::Weight.new(2.25567, "kg").to_f
|
22
22
|
# => 2.25567 kg
|
23
23
|
#
|
24
24
|
# @return [Measurement]
|
@@ -29,7 +29,7 @@ module UnitMeasurements
|
|
29
29
|
# Converts quantity of the measurement to +Rational+.
|
30
30
|
#
|
31
31
|
# @example
|
32
|
-
# UnitMeasurements::Weight.new(2.25567,
|
32
|
+
# UnitMeasurements::Weight.new(2.25567, "kg").to_r
|
33
33
|
# => 225567/100000 kg
|
34
34
|
#
|
35
35
|
# @return [Measurement]
|
@@ -40,7 +40,7 @@ module UnitMeasurements
|
|
40
40
|
# Converts quantity of the measurement to +Complex+.
|
41
41
|
#
|
42
42
|
# @example
|
43
|
-
# UnitMeasurements::Weight.new(2.25567,
|
43
|
+
# UnitMeasurements::Weight.new(2.25567, "kg").to_c
|
44
44
|
# => 2.25567+0i kg
|
45
45
|
#
|
46
46
|
# @return [Measurement]
|
@@ -51,7 +51,7 @@ module UnitMeasurements
|
|
51
51
|
# Converts quantity of the measurement to +BigDecimal+.
|
52
52
|
#
|
53
53
|
# @example
|
54
|
-
# UnitMeasurements::Weight.new(2.25567,
|
54
|
+
# UnitMeasurements::Weight.new(2.25567, "kg").to_d
|
55
55
|
# => 2.25567 kg
|
56
56
|
#
|
57
57
|
# @return [Measurement]
|
@@ -12,9 +12,9 @@ module UnitMeasurements
|
|
12
12
|
# formatting the measurement
|
13
13
|
#
|
14
14
|
# @example
|
15
|
-
# UnitMeasurements::Weight.parse("2 kg").to(
|
15
|
+
# UnitMeasurements::Weight.parse("2 kg").to("st").format
|
16
16
|
# => "0.31 st"
|
17
|
-
# UnitMeasurements::Weight.parse("2 kg").to(
|
17
|
+
# UnitMeasurements::Weight.parse("2 kg").to("st").format("%.4<quantity>f %<unit>s")
|
18
18
|
# => "0.3149 st"
|
19
19
|
#
|
20
20
|
# @param [String] format
|
@@ -8,7 +8,7 @@ module UnitMeasurements
|
|
8
8
|
# quantity is rounded to `Integer`.
|
9
9
|
#
|
10
10
|
# @example
|
11
|
-
# UnitMeasurements::Weight.new(1,
|
11
|
+
# UnitMeasurements::Weight.new(1, "g").convert_to("st").round(4)
|
12
12
|
# => 0.0002 st
|
13
13
|
#
|
14
14
|
# @param [Integer] ndigits
|
@@ -21,7 +21,7 @@ module UnitMeasurements
|
|
21
21
|
# Returns absolute value of the measurement quantity.
|
22
22
|
#
|
23
23
|
# @example
|
24
|
-
# UnitMeasurements::Length.new(-17.625,
|
24
|
+
# UnitMeasurements::Length.new(-17.625, "m").abs
|
25
25
|
# => 17.625 m
|
26
26
|
#
|
27
27
|
# @return [Measurement]
|
@@ -32,7 +32,7 @@ module UnitMeasurements
|
|
32
32
|
# Rounds quantity of the measurement to next lower integer.
|
33
33
|
#
|
34
34
|
# @example
|
35
|
-
# UnitMeasurements::Length.new(17.625,
|
35
|
+
# UnitMeasurements::Length.new(17.625, "m").floor
|
36
36
|
# => 17 m
|
37
37
|
#
|
38
38
|
# @return [Measurement]
|
@@ -43,7 +43,7 @@ module UnitMeasurements
|
|
43
43
|
# Rounds quantity of the measurement to next higher integer.
|
44
44
|
#
|
45
45
|
# @example
|
46
|
-
# UnitMeasurements::Length.new(17.625,
|
46
|
+
# UnitMeasurements::Length.new(17.625, "m").ceil
|
47
47
|
# => 18 m
|
48
48
|
#
|
49
49
|
# @return [Measurement]
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# -*- warn_indent: true -*-
|
4
4
|
|
5
5
|
UnitMeasurements::AmountOfSubstance = UnitMeasurements.build do
|
6
|
-
si_unit
|
6
|
+
si_unit "mol", aliases: ["mole", "moles"]
|
7
7
|
|
8
|
-
unit
|
8
|
+
unit "NA", value: "1.6605389210322e-24 mol", aliases: ["avogadro constant"]
|
9
9
|
end
|
@@ -3,11 +3,11 @@
|
|
3
3
|
# -*- warn_indent: true -*-
|
4
4
|
|
5
5
|
UnitMeasurements::Area = UnitMeasurements.build do
|
6
|
-
base
|
6
|
+
base "m²", aliases: ["m^2", "sq m", "square meter", "square meters", "square metre", "square metres"]
|
7
7
|
|
8
|
-
unit
|
9
|
-
unit
|
10
|
-
unit
|
11
|
-
unit
|
12
|
-
unit
|
8
|
+
unit "km²", value: "1e+6 m²", aliases: ["km^2", "sq km", "square kilometer", "square kilometers", "square kilometre", "square kilometres"]
|
9
|
+
unit "in²", value: "0.00064516 m²", aliases: ["in^2", "sq in", "square inch", "square inches"]
|
10
|
+
unit "ft²", value: "144 in²", aliases: ["ft^2", "sq ft", "square foot", "square feet"]
|
11
|
+
unit "yd²", value: "9 ft²", aliases: ["yd^2", "sq yd", "square yard", "square yards"]
|
12
|
+
unit "mi²", value: "3097600 yd²", aliases: ["mi^2", "sq mi", "square mile", "square miles"]
|
13
13
|
end
|
@@ -3,11 +3,11 @@
|
|
3
3
|
# -*- warn_indent: true -*-
|
4
4
|
|
5
5
|
UnitMeasurements::Density = UnitMeasurements.build do
|
6
|
-
base
|
6
|
+
base "g/m³", aliases: ["g/m^3", "g·m⁻³", "gram per cubic meter", "grams per cubic meter", "gramme per cubic metre", "grammes per cubic metre"]
|
7
7
|
|
8
|
-
unit
|
9
|
-
unit
|
8
|
+
unit "g/l", value: "1 kg/m³", aliases: ["g·l⁻¹", "gram per liter", "grams per liter", "gramme per litre", "grammes per litre"]
|
9
|
+
unit "g/ml", value: "1000 g/l", aliases: ["g·ml⁻¹", "gram per milliliter", "grams per milliliter", "gramme per millilitre", "grammes per millilitre"]
|
10
10
|
|
11
|
-
unit
|
12
|
-
unit
|
11
|
+
unit "kg/m³", value: "1000 g/m³", aliases: ["kg/m^3", "kg·m⁻³", "kilogram per cubic meter", "kilograms per cubic meter", "kilogramme per cubic metre", "kilogrammes per cubic metre"]
|
12
|
+
unit "kg/l", value: "1e+6 g/m³", aliases: ["kg·l⁻¹", "kilogram per liter", "kilograms per liter", "kilogramme per litre", "kilogrammes per litre"]
|
13
13
|
end
|
@@ -3,9 +3,9 @@
|
|
3
3
|
# -*- warn_indent: true -*-
|
4
4
|
|
5
5
|
UnitMeasurements::ElectricCurrent = UnitMeasurements.build do
|
6
|
-
si_unit
|
6
|
+
si_unit "A", aliases: ["amp", "ampere", "amperes"]
|
7
7
|
|
8
|
-
unit
|
9
|
-
unit
|
10
|
-
unit
|
8
|
+
unit "abA", value: "10 A", aliases: ["abampere", "abamperes"]
|
9
|
+
unit "Bi", value: "10 A", aliases: ["biot", "biots"]
|
10
|
+
unit "statA", value: "3.33564e-10 A", aliases: ["statampere", "statamperes"]
|
11
11
|
end
|
@@ -3,12 +3,12 @@
|
|
3
3
|
# -*- warn_indent: true -*-
|
4
4
|
|
5
5
|
UnitMeasurements::Force = UnitMeasurements.build do
|
6
|
-
si_unit
|
6
|
+
si_unit "N", aliases: ["newton", "newtons"] # kg·m·s⁻²
|
7
7
|
|
8
|
-
unit
|
9
|
-
unit
|
10
|
-
unit
|
11
|
-
unit
|
12
|
-
unit
|
13
|
-
unit
|
8
|
+
unit "tf", value: "8896.443230521 N", aliases: ["tonne-force"]
|
9
|
+
unit "dyn", value: "1e-5 N", aliases: ["dyne", "dynes"]
|
10
|
+
unit "kgf", value: "9.80665 N", aliases: ["kilogram-force", "kilogramme-force"]
|
11
|
+
unit "ozf", value: "0.27801385095378125 N", aliases: ["ounce-force"]
|
12
|
+
unit "lbf", value: "4.4482216152605 N", aliases: ["pound-force"]
|
13
|
+
unit "pdl", value: "0.138254954376 N", aliases: ["poundal", "poundals"]
|
14
14
|
end
|
@@ -3,10 +3,10 @@
|
|
3
3
|
# -*- warn_indent: true -*-
|
4
4
|
|
5
5
|
UnitMeasurements::Length = UnitMeasurements.build do
|
6
|
-
si_unit
|
6
|
+
si_unit "m", aliases: ["meter", "metre", "meters", "metres"]
|
7
7
|
|
8
|
-
unit
|
9
|
-
unit
|
10
|
-
unit
|
11
|
-
unit
|
8
|
+
unit "in", value: "25.4 mm", aliases: ['"', "inch", "inches"]
|
9
|
+
unit "ft", value: "12 in", aliases: ["'", "foot", "feet"]
|
10
|
+
unit "yd", value: "3 ft", aliases: ["yard", "yards"]
|
11
|
+
unit "mi", value: "1760 yd", aliases: ["mile", "miles"]
|
12
12
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# -*- warn_indent: true -*-
|
4
4
|
|
5
5
|
UnitMeasurements::LuminousIntensity = UnitMeasurements.build do
|
6
|
-
si_unit
|
6
|
+
si_unit "cd", aliases: ["candela", "candelas"]
|
7
7
|
|
8
|
-
unit
|
8
|
+
unit "hk", value: "0.92 cd", aliases: ["hefnerkerze"]
|
9
9
|
end
|
@@ -3,16 +3,16 @@
|
|
3
3
|
# -*- warn_indent: true -*-
|
4
4
|
|
5
5
|
UnitMeasurements::PlaneAngle = UnitMeasurements.build do
|
6
|
-
si_unit
|
6
|
+
si_unit "rad", aliases: ["radian", "radians"]
|
7
7
|
|
8
|
-
unit
|
9
|
-
unit
|
10
|
-
unit
|
11
|
-
unit
|
12
|
-
unit
|
8
|
+
unit "deg", value: [(Math::PI / 180), "rad"], aliases: ["°", "degree", "degrees"] # (π / 180) rad
|
9
|
+
unit "gon", value: [(Math::PI / 200), "rad"], aliases: ["ᵍ", "grad", "gradian", "gradians"] # (π / 200) rad
|
10
|
+
unit "cir", value: "360 deg", aliases: ["circle", "circles"] # (2 * π) rad
|
11
|
+
unit "mil", value: "1/6400 cir", aliases: ["mils"] # ((2 * π) / 6400) rad
|
12
|
+
unit "rev", value: "1 cir", aliases: ["revolution", "revolutions"] # (2 * π) rad
|
13
13
|
|
14
|
-
unit
|
14
|
+
unit "brad", value: [(Math::PI / 128), "rad"], aliases: ["b°", "bdeg", "binary degree", "binary radian", "binary degrees", "binary radians"] # (π / 128) rad
|
15
15
|
|
16
|
-
unit
|
17
|
-
unit
|
16
|
+
unit "arcmin", value: "1/60 deg", aliases: ["′", "amin", "arcminute", "arcminutes"] # ((π / 180) / 60) rad
|
17
|
+
unit "arcsec", value: "1/60 arcmin", aliases: ["″", "asec", "arcsecond", "arcseconds"] # ((π / 180) / 3600) rad
|
18
18
|
end
|
@@ -3,10 +3,10 @@
|
|
3
3
|
# -*- warn_indent: true -*-
|
4
4
|
|
5
5
|
UnitMeasurements::Quantity = UnitMeasurements.build do
|
6
|
-
base
|
6
|
+
base "pc", aliases: ["pcs", "piece", "pieces"]
|
7
7
|
|
8
|
-
unit
|
9
|
-
unit
|
10
|
-
unit
|
11
|
-
unit
|
8
|
+
unit "pr", value: "2 pc", aliases: ["pair", "pairs"]
|
9
|
+
unit "dz", value: "6 pr", aliases: ["doz", "dozen", "dozens"]
|
10
|
+
unit "gr", value: "12 doz", aliases: ["gross", "grosses"]
|
11
|
+
unit "gg", value: "12 gr", aliases: ["great gross", "great grosses", "grand gross", "grand grosses", "dozen gross", "dozen grosses"]
|
12
12
|
end
|
@@ -3,10 +3,10 @@
|
|
3
3
|
# -*- warn_indent: true -*-
|
4
4
|
|
5
5
|
UnitMeasurements::SolidAngle = UnitMeasurements.build do
|
6
|
-
si_unit
|
6
|
+
si_unit "sr", aliases: ["steradian", "steradians"]
|
7
7
|
|
8
|
-
unit
|
9
|
-
unit
|
10
|
-
unit
|
11
|
-
unit
|
8
|
+
unit "sp", value: [(4 * Math::PI), "sr"], aliases: ["spat", "spats"] # (4 * π) sr
|
9
|
+
unit "deg²", value: [((Math::PI / 180) ** 2), "sr"], aliases: ["(°)²", "sq °", "square degree", "square degrees"] # (π / 180)² sr
|
10
|
+
unit "arcmin²", value: [(Rational(1, 60) ** 2), "deg²"], aliases: ["(′)²", "sq ′", "square arcminute", "square arcminutes"] # ((π / 180) * (1 / 60))² sr
|
11
|
+
unit "arcsec²", value: [(Rational(1, 60) ** 2), "arcmin²"], aliases: ["(″)²", "sq ″", "square arcsecond", "square arcseconds"] # ((π / 180) * (1 / 3600))² sr
|
12
12
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# -*- warn_indent: true -*-
|
4
4
|
|
5
5
|
UnitMeasurements::SoundLevel = UnitMeasurements.build do
|
6
|
-
si_unit
|
6
|
+
si_unit "B", aliases: ["bel", "bels"]
|
7
7
|
|
8
|
-
unit
|
8
|
+
unit "Np", value: [(20 / Math.log(10)), "dB"], aliases: ["neper", "nepers"] # (20 / ln(10)) dB
|
9
9
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# -*- warn_indent: true -*-
|
4
4
|
|
5
5
|
UnitMeasurements::Temperature = UnitMeasurements.build do
|
6
|
-
|
6
|
+
si_unit "K", aliases: ["kelvin", "kelvins"]
|
7
7
|
|
8
|
-
|
8
|
+
unit "°R", value: "5/9 K", aliases: ["R", "°Ra", "Ra", "rankine"]
|
9
9
|
end
|
@@ -3,16 +3,16 @@
|
|
3
3
|
# -*- warn_indent: true -*-
|
4
4
|
|
5
5
|
UnitMeasurements::Time = UnitMeasurements.build do
|
6
|
-
si_unit
|
6
|
+
si_unit "s", aliases: ["sec", "second", "seconds"]
|
7
7
|
|
8
|
-
unit
|
9
|
-
unit
|
10
|
-
unit
|
11
|
-
unit
|
12
|
-
unit
|
13
|
-
unit
|
14
|
-
unit
|
15
|
-
unit
|
16
|
-
unit
|
17
|
-
unit
|
8
|
+
unit "h", value: "60 min", aliases: ["hr", "hour", "hours"]
|
9
|
+
unit "d", value: "24 h", aliases: ["day", "days"]
|
10
|
+
unit "wk", value: "7 d", aliases: ["week", "weeks"]
|
11
|
+
unit "fn", value: "2 wk", aliases: ["4tnite", "fortnight", "fortnights"]
|
12
|
+
unit "mo", value: "30.4167 d", aliases: ["month", "months"]
|
13
|
+
unit "yr", value: "365 d", aliases: ["y", "year", "years"]
|
14
|
+
unit "min", value: "60 s", aliases: ["minute", "minutes"]
|
15
|
+
unit "qtr", value: "3 mo", aliases: ["quarter", "quarters"]
|
16
|
+
unit "dec", value: "10 y", aliases: ["decade", "decades"]
|
17
|
+
unit "cent", value: "10 dec", aliases: ["century", "centuries"]
|
18
18
|
end
|
@@ -3,16 +3,16 @@
|
|
3
3
|
# -*- warn_indent: true -*-
|
4
4
|
|
5
5
|
UnitMeasurements::Volume = UnitMeasurements.build do
|
6
|
-
si_unit
|
6
|
+
si_unit "l", aliases: ["liter", "litre", "liters", "litres"]
|
7
7
|
|
8
|
-
unit
|
9
|
-
unit
|
10
|
-
unit
|
11
|
-
unit
|
12
|
-
unit
|
8
|
+
unit "m³", value: "1000 l", aliases: ["m^3", "cu m", "cubic meter", "cubic meters", "cubic metre", "cubic metres"]
|
9
|
+
unit "mm³", value: "1e-9 m³", aliases: ["mm^3", "cu mm", "cubic millimeter", "cubic millimeters", "cubic millimetre", "cubic millimetres"]
|
10
|
+
unit "cm³", value: "1e-6 m³", aliases: ["cm^3", "cu cm", "cubic centimeter", "cubic centimeters", "cubic centimetre", "cubic centimetres"]
|
11
|
+
unit "dm³", value: "1 l", aliases: ["dm^3", "cu dm", "cubic decimeter", "cubic decimeters", "cubic decimetre", "cubic decimetres"]
|
12
|
+
unit "km³", value: "1e+9 m³", aliases: ["km^3", "cu km", "cubic kilometer", "cubic kilometers", "cubic kilometre", "cubic kilometres"]
|
13
13
|
|
14
|
-
unit
|
15
|
-
unit
|
16
|
-
unit
|
17
|
-
unit
|
14
|
+
unit "in³", value: "16.387064 ml", aliases: ["in^3", "cu in", "cubic inch", "cubic inches"]
|
15
|
+
unit "ft³", value: "1728 in³", aliases: ["ft^3", "cu ft", "cubic foot", "cubic feet"]
|
16
|
+
unit "yd³", value: "27 ft³", aliases: ["yd^3", "cu yd", "cubic yard", "cubic yards"]
|
17
|
+
unit "mi³", value: "5451776000 yd³", aliases: ["mi^3", "cu mi", "cubic mile", "cubic miles"]
|
18
18
|
end
|
@@ -3,8 +3,8 @@
|
|
3
3
|
# -*- warn_indent: true -*-
|
4
4
|
|
5
5
|
UnitMeasurements::Weight = UnitMeasurements.build do
|
6
|
-
si_unit
|
6
|
+
si_unit "g", aliases: ["gram", "grams", "gramme", "grammes"]
|
7
7
|
|
8
|
-
unit
|
9
|
-
unit
|
8
|
+
unit "q", value: "100 kg", aliases: ["quintal", "quintals"]
|
9
|
+
unit "t", value: "10 q", aliases: ["tonne", "tonnes", "metric tonne", "metric tonnes"]
|
10
10
|
end
|