unit_measurements 2.6.1 → 3.0.0
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 +24 -0
- data/Gemfile.lock +1 -1
- data/{LICENSE → LICENSE.md} +1 -1
- data/README.md +76 -76
- 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/measurement.rb +9 -1
- data/lib/unit_measurements/unit_group_builder.rb +0 -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
- data/unit_measurements.gemspec +1 -1
- data/units.md +16 -17
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b48c60ef57c1c3c3da286747f91effb58b512a5c827c1867ca6266446ff25722
|
4
|
+
data.tar.gz: 68e0a02544ba31a167ba99ebe94ba44e10876a3fb8922a65bae740becb770d22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bef997801950b327b2665be18acb6836598606a28860945a7486dfd50afb5583e43b0fee050c50e3955272c88de6cf933131c9fa6e0e760e4ced83a59d68b164
|
7
|
+
data.tar.gz: '09c708ffbc5fa6f74dd30e5b0feee871826b15508bdec4de5c84b75246712a0379d5266f1685defa6fb6b161ef3d14b25f28422fb70c8e3c0f3e13b775612b5b'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
## [3.0.0](https://github.com/shivam091/unit_measurements/compare/v2.6.2...v3.0.0) - 2023-08-25
|
2
|
+
|
3
|
+
### What's new
|
4
|
+
|
5
|
+
- Added method `Measurement.name` to get humanized name of the unit group.
|
6
|
+
- Raised `BaseError` in `Measurement.unit_group`.
|
7
|
+
- Added aliases `in`, `as`, `in!`, `as` for `convert_to` and `convert_to!` methods.
|
8
|
+
|
9
|
+
### What's changed
|
10
|
+
|
11
|
+
- Moved LICENSE to markdown file.
|
12
|
+
- Replaced `$LOAD_PATH` by shorthand `$:`
|
13
|
+
- Replaced `base` method by `unit`.
|
14
|
+
|
15
|
+
----------
|
16
|
+
|
17
|
+
## [2.6.2](https://github.com/shivam091/unit_measurements/compare/v2.6.1...v2.6.2) - 2023-08-25
|
18
|
+
|
19
|
+
### What's changed
|
20
|
+
|
21
|
+
- Replaced `String` by `Symbol` in unit names and symbols.
|
22
|
+
|
23
|
+
----------
|
24
|
+
|
1
25
|
## [2.6.1](https://github.com/shivam091/unit_measurements/compare/v2.6.0...v2.6.1) - 2023-08-24
|
2
26
|
|
3
27
|
### What's changed
|
data/Gemfile.lock
CHANGED
data/{LICENSE → LICENSE.md}
RENAMED
data/README.md
CHANGED
@@ -65,34 +65,35 @@ 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
|
|
72
72
|
**Converting to other units:**
|
73
73
|
|
74
74
|
This gem allows you to convert among units of same unit group.
|
75
|
-
You can convert measurement to other unit using `#convert_to`
|
76
|
-
|
75
|
+
You can convert measurement to other unit using `#convert_to`
|
76
|
+
(aliased as `#to`, `#in`, and `as`) or `#convert_to!`
|
77
|
+
(aliased as `#to!`, `#in!`, and `as!`) methods.
|
77
78
|
|
78
79
|
You can use `#convert_to` as:
|
79
80
|
|
80
81
|
```ruby
|
81
|
-
UnitMeasurements::Weight.new(1,
|
82
|
+
UnitMeasurements::Weight.new(1, :kg).convert_to(:g)
|
82
83
|
#=> 1000.0 g
|
83
84
|
```
|
84
85
|
|
85
86
|
If you want to modify measurement object itself, you can use `#convert_to!` method as:
|
86
87
|
|
87
88
|
```ruby
|
88
|
-
UnitMeasurements::Weight.new(1,
|
89
|
+
UnitMeasurements::Weight.new(1, :kg).convert_to!(:g)
|
89
90
|
#=> 1000.0 g
|
90
91
|
```
|
91
92
|
|
92
93
|
You can also chain call of `#convert_to` and `#convert_to!` methods as:
|
93
94
|
|
94
95
|
```ruby
|
95
|
-
UnitMeasurements::Weight.new(1,
|
96
|
+
UnitMeasurements::Weight.new(1, :kg).convert_to(:g).convert_to(:t).convert_to!(:q)
|
96
97
|
#=> 0.01 q
|
97
98
|
```
|
98
99
|
|
@@ -117,11 +118,11 @@ UnitMeasurements::Weight.parse("1 kg in g")
|
|
117
118
|
**Parse rational numbers, source unit, and (or) target unit:**
|
118
119
|
|
119
120
|
```ruby
|
120
|
-
UnitMeasurements::Weight.new(Rational(2, 3),
|
121
|
+
UnitMeasurements::Weight.new(Rational(2, 3), :kg).convert_to(:g)
|
121
122
|
#=> 666.666666666667 g
|
122
|
-
UnitMeasurements::Weight.new("2/3",
|
123
|
+
UnitMeasurements::Weight.new("2/3", :kg).convert_to(:g)
|
123
124
|
#=> 666.666666666667 g
|
124
|
-
UnitMeasurements::Weight.parse("2/3 kg").convert_to(
|
125
|
+
UnitMeasurements::Weight.parse("2/3 kg").convert_to(:g)
|
125
126
|
#=> 666.666666666667 g
|
126
127
|
UnitMeasurements::Weight.parse("2/3 kg to g")
|
127
128
|
#=> 666.666666666667 g
|
@@ -130,11 +131,11 @@ UnitMeasurements::Weight.parse("2/3 kg to g")
|
|
130
131
|
**Parse complex numbers, source unit, and (or) target unit:**
|
131
132
|
|
132
133
|
```ruby
|
133
|
-
UnitMeasurements::Weight.new(Complex(2, 3),
|
134
|
+
UnitMeasurements::Weight.new(Complex(2, 3), :kg).convert_to(:g)
|
134
135
|
#=> 2000.0+3000.0i g
|
135
|
-
UnitMeasurements::Weight.new("2+3i",
|
136
|
+
UnitMeasurements::Weight.new("2+3i", :kg).convert_to(:g)
|
136
137
|
#=> 2000.0+3000.0i g
|
137
|
-
UnitMeasurements::Weight.parse("2+3i kg").convert_to(
|
138
|
+
UnitMeasurements::Weight.parse("2+3i kg").convert_to(:g)
|
138
139
|
#=> 2000.0+3000.0i g
|
139
140
|
UnitMeasurements::Weight.parse("2+3i kg to g")
|
140
141
|
#=> 2000.0+3000.0i g
|
@@ -143,11 +144,11 @@ UnitMeasurements::Weight.parse("2+3i kg to g")
|
|
143
144
|
**Parse scientific numbers, source unit, and (or) target unit:**
|
144
145
|
|
145
146
|
```ruby
|
146
|
-
UnitMeasurements::Weight.new(BigDecimal(2),
|
147
|
+
UnitMeasurements::Weight.new(BigDecimal(2), :kg).convert_to(:g)
|
147
148
|
#=> 2000.0 g
|
148
|
-
UnitMeasurements::Weight.new(0.2e1,
|
149
|
+
UnitMeasurements::Weight.new(0.2e1, :kg).convert_to(:g)
|
149
150
|
#=> 2000.0 g
|
150
|
-
UnitMeasurements::Weight.parse("0.2e1 kg").convert_to(
|
151
|
+
UnitMeasurements::Weight.parse("0.2e1 kg").convert_to(:g)
|
151
152
|
#=> 2000.0 g
|
152
153
|
UnitMeasurements::Weight.parse("0.2e1 kg to g")
|
153
154
|
#=> 2000.0 g
|
@@ -156,9 +157,9 @@ UnitMeasurements::Weight.parse("0.2e1 kg to g")
|
|
156
157
|
**Parse ratios, source unit, and (or) target unit:**
|
157
158
|
|
158
159
|
```ruby
|
159
|
-
UnitMeasurements::Weight.new("1:2",
|
160
|
+
UnitMeasurements::Weight.new("1:2", :kg).convert_to(:g)
|
160
161
|
#=> 500.0 g
|
161
|
-
UnitMeasurements::Weight.parse("1:2 kg").convert_to(
|
162
|
+
UnitMeasurements::Weight.parse("1:2 kg").convert_to(:g)
|
162
163
|
#=> 500.0 g
|
163
164
|
UnitMeasurements::Weight.parse("1:2 kg to g")
|
164
165
|
#=> 500.0 g
|
@@ -167,15 +168,15 @@ UnitMeasurements::Weight.parse("1:2 kg to g")
|
|
167
168
|
**Parse fractional notations, source unit, and (or) target unit:**
|
168
169
|
|
169
170
|
```ruby
|
170
|
-
UnitMeasurements::Weight.new("1/2",
|
171
|
+
UnitMeasurements::Weight.new("1/2", :kg).convert_to(:g)
|
171
172
|
#=> 500.0 g
|
172
|
-
UnitMeasurements::Weight.parse("1/2 kg").convert_to(
|
173
|
+
UnitMeasurements::Weight.parse("1/2 kg").convert_to(:g)
|
173
174
|
#=> 500.0 g
|
174
175
|
UnitMeasurements::Weight.parse("1/2 kg to g")
|
175
176
|
#=> 500.0 g
|
176
|
-
UnitMeasurements::Weight.new("½",
|
177
|
+
UnitMeasurements::Weight.new("½", :kg).convert_to(:g)
|
177
178
|
#=> 500.0 g
|
178
|
-
UnitMeasurements::Weight.parse("½ kg").convert_to(
|
179
|
+
UnitMeasurements::Weight.parse("½ kg").convert_to(:g)
|
179
180
|
#=> 500.0 g
|
180
181
|
UnitMeasurements::Weight.parse("½ kg to g")
|
181
182
|
#=> 500.0 g
|
@@ -184,15 +185,15 @@ UnitMeasurements::Weight.parse("½ kg to g")
|
|
184
185
|
**Parse mixed fractional notations, source unit, and (or) target unit:**
|
185
186
|
|
186
187
|
```ruby
|
187
|
-
UnitMeasurements::Weight.new("2 1/2",
|
188
|
+
UnitMeasurements::Weight.new("2 1/2", :kg).convert_to(:g)
|
188
189
|
#=> 2500.0 g
|
189
|
-
UnitMeasurements::Weight.parse("2 1/2 kg").convert_to(
|
190
|
+
UnitMeasurements::Weight.parse("2 1/2 kg").convert_to(:g)
|
190
191
|
#=> 2500.0 g
|
191
192
|
UnitMeasurements::Weight.parse("2 1/2 kg to g")
|
192
193
|
#=> 2500.0 g
|
193
|
-
UnitMeasurements::Weight.new("2 ½",
|
194
|
+
UnitMeasurements::Weight.new("2 ½", :kg).convert_to(:g)
|
194
195
|
#=> 2500.0 g
|
195
|
-
UnitMeasurements::Weight.parse("2 ½ kg").convert_to(
|
196
|
+
UnitMeasurements::Weight.parse("2 ½ kg").convert_to(:g)
|
196
197
|
#=> 2500.0 g
|
197
198
|
UnitMeasurements::Weight.parse("2 ½ kg to g")
|
198
199
|
#=> 2500.0 g
|
@@ -203,15 +204,15 @@ Supported special characters for fractional notations are `¼`, `½`, `¾`, `⅓
|
|
203
204
|
**Parse exponents, source unit, and (or) target unit:**
|
204
205
|
|
205
206
|
```ruby
|
206
|
-
UnitMeasurements::Weight.new("2e+2",
|
207
|
+
UnitMeasurements::Weight.new("2e+2", :kg).convert_to(:g)
|
207
208
|
#=> 200000.0 g
|
208
|
-
UnitMeasurements::Weight.parse("2e² kg").convert_to(
|
209
|
+
UnitMeasurements::Weight.parse("2e² kg").convert_to(:g)
|
209
210
|
#=> 200000.0 g
|
210
211
|
UnitMeasurements::Weight.parse("2e+2 kg to g")
|
211
212
|
#=> 200000.0 g
|
212
|
-
UnitMeasurements::Weight.new("2e⁺²",
|
213
|
+
UnitMeasurements::Weight.new("2e⁺²", :kg).convert_to(:g)
|
213
214
|
#=> 200000.0 g
|
214
|
-
UnitMeasurements::Weight.parse("2e⁺2 kg").convert_to(
|
215
|
+
UnitMeasurements::Weight.parse("2e⁺2 kg").convert_to(:g)
|
215
216
|
#=> 200000.0 g
|
216
217
|
UnitMeasurements::Weight.parse("2e⁻² kg to g")
|
217
218
|
#=> 20.0 g
|
@@ -225,24 +226,31 @@ If you want to format measurement to certain format, you can use `#format` metho
|
|
225
226
|
If format is not specified, it defaults to `"%.2<value>f %<unit>s"`.
|
226
227
|
|
227
228
|
```ruby
|
228
|
-
UnitMeasurements::Weight.parse("2 kg").to(
|
229
|
+
UnitMeasurements::Weight.parse("2 kg").to(:st).format
|
229
230
|
#=> "0.31 st"
|
230
|
-
UnitMeasurements::Weight.parse("2 kg").to(
|
231
|
+
UnitMeasurements::Weight.parse("2 kg").to(:st).format("%.4<quantity>f %<unit>s")
|
231
232
|
#=> "0.3149 st"
|
232
|
-
UnitMeasurements::Weight.parse("2 kg").to(
|
233
|
+
UnitMeasurements::Weight.parse("2 kg").to(:st).format("%.4<quantity>f")
|
233
234
|
#=> "0.3149"
|
234
235
|
```
|
235
236
|
|
236
237
|
**Extract the unit and the quantity from measurement:**
|
237
238
|
|
238
239
|
```ruby
|
239
|
-
weight = UnitMeasurements::Weight.new(1,
|
240
|
+
weight = UnitMeasurements::Weight.new(1, :kg)
|
240
241
|
weight.quantity
|
241
242
|
#=> 1
|
242
243
|
weight.unit
|
243
244
|
#=> #<UnitMeasurements::Unit: kg (kilogram, kilogramme, kilogrammes, kilograms)>
|
244
245
|
```
|
245
246
|
|
247
|
+
**See humanized name of the unit group:**
|
248
|
+
|
249
|
+
```ruby
|
250
|
+
UnitMeasurements::Weight.name
|
251
|
+
#=> weight
|
252
|
+
```
|
253
|
+
|
246
254
|
**See all units of the unit group:**
|
247
255
|
|
248
256
|
```ruby
|
@@ -271,35 +279,35 @@ the unit group. `#unit_for!` method returns error if a unit is not present in th
|
|
271
279
|
unit group.
|
272
280
|
|
273
281
|
```ruby
|
274
|
-
UnitMeasurements::Weight.unit_for(
|
282
|
+
UnitMeasurements::Weight.unit_for(:g)
|
275
283
|
#=> #<UnitMeasurements::Unit: g (gram, gramme, grammes, grams)>
|
276
|
-
UnitMeasurements::Weight.unit_for(
|
284
|
+
UnitMeasurements::Weight.unit_for(:z)
|
277
285
|
#=> nil
|
278
|
-
UnitMeasurements::Weight.unit_for!(
|
286
|
+
UnitMeasurements::Weight.unit_for!(:g)
|
279
287
|
#=> #<UnitMeasurements::Unit: g (gram, gramme, grammes, grams)>
|
280
|
-
UnitMeasurements::Weight.unit_for!(
|
288
|
+
UnitMeasurements::Weight.unit_for!(:z)
|
281
289
|
#=> Invalid unit: 'z'. (UnitMeasurements::UnitError)
|
282
290
|
```
|
283
291
|
|
284
292
|
**Finding whether the unit is defined within the unit group:**
|
285
293
|
|
286
294
|
```ruby
|
287
|
-
UnitMeasurements::Weight.defined?(
|
295
|
+
UnitMeasurements::Weight.defined?(:g)
|
288
296
|
#=> true
|
289
|
-
UnitMeasurements::Weight.defined?(
|
297
|
+
UnitMeasurements::Weight.defined?(:kg)
|
290
298
|
#=> true
|
291
|
-
UnitMeasurements::Weight.defined?(
|
299
|
+
UnitMeasurements::Weight.defined?(:gramme)
|
292
300
|
#=> false
|
293
301
|
```
|
294
302
|
|
295
303
|
**Check if the unit is a valid unit or alias within the unit group:**
|
296
304
|
|
297
305
|
```ruby
|
298
|
-
UnitMeasurements::Weight.unit_or_alias?(
|
306
|
+
UnitMeasurements::Weight.unit_or_alias?(:g)
|
299
307
|
#=> true
|
300
|
-
UnitMeasurements::Weight.unit_or_alias?(
|
308
|
+
UnitMeasurements::Weight.unit_or_alias?(:kg)
|
301
309
|
#=> true
|
302
|
-
UnitMeasurements::Weight.unit_or_alias?(
|
310
|
+
UnitMeasurements::Weight.unit_or_alias?(:gramme)
|
303
311
|
#=> true
|
304
312
|
```
|
305
313
|
|
@@ -319,9 +327,9 @@ UnitMeasurements::Weight.parse("1 kg") <= UnitMeasurements::Weight.parse("0.5 kg
|
|
319
327
|
#=> false
|
320
328
|
UnitMeasurements::Weight.parse("1 kg") >= UnitMeasurements::Weight.parse("0.5 kg")
|
321
329
|
#=> true
|
322
|
-
UnitMeasurements::Length.new(1,
|
330
|
+
UnitMeasurements::Length.new(1, :ft).between?(UnitMeasurements::Length.new(12, :in), UnitMeasurements::Length.new(24, :in))
|
323
331
|
#=> true
|
324
|
-
UnitMeasurements::Length.new(1,
|
332
|
+
UnitMeasurements::Length.new(1, :ft).clamp(UnitMeasurements::Length.new(13, :in), UnitMeasurements::Length.new(24, :in))
|
325
333
|
#=> 13 in
|
326
334
|
```
|
327
335
|
|
@@ -338,13 +346,13 @@ measurement by either other compatible measurement or number.
|
|
338
346
|
4. `#/` - Divides the measurement quantity by other measurement quantity or number.
|
339
347
|
|
340
348
|
```ruby
|
341
|
-
UnitMeasurements::Weight.new(1,
|
349
|
+
UnitMeasurements::Weight.new(1, :kg) + UnitMeasurements::Weight.new(1, :g)
|
342
350
|
#=> 1.001 kg
|
343
|
-
UnitMeasurements::Weight.new(2,
|
351
|
+
UnitMeasurements::Weight.new(2, :kg) - 1
|
344
352
|
#=> 1 kg
|
345
|
-
UnitMeasurements::Weight.new(2,
|
353
|
+
UnitMeasurements::Weight.new(2, :kg) * 2
|
346
354
|
#=> 4 kg
|
347
|
-
UnitMeasurements::Weight.new(4,
|
355
|
+
UnitMeasurements::Weight.new(4, :kg) / UnitMeasurements::Weight.new(2, :kg)
|
348
356
|
#=> 2 kg
|
349
357
|
```
|
350
358
|
|
@@ -359,13 +367,13 @@ You can perform mathematical operations on the measurements.
|
|
359
367
|
4. `#ceil` - Rounds quantity of the measurement to next higher integer.
|
360
368
|
|
361
369
|
```ruby
|
362
|
-
UnitMeasurements::Weight.new(1,
|
370
|
+
UnitMeasurements::Weight.new(1, :g).convert_to(:st).round(4)
|
363
371
|
#=> 0.0002 st
|
364
|
-
UnitMeasurements::Length.new(-17.625,
|
372
|
+
UnitMeasurements::Length.new(-17.625, :m).abs
|
365
373
|
#=> 17.625 m
|
366
|
-
UnitMeasurements::Length.new(17.625,
|
374
|
+
UnitMeasurements::Length.new(17.625, :m).floor
|
367
375
|
#=> 17 m
|
368
|
-
UnitMeasurements::Length.new(17.625,
|
376
|
+
UnitMeasurements::Length.new(17.625, :m).ceil
|
369
377
|
#=> 18 m
|
370
378
|
```
|
371
379
|
|
@@ -375,15 +383,15 @@ You can convert measurement quantity directly to other numeric types viz.
|
|
375
383
|
`Integer`, `BigDecimal`, `Rational`, `Complex`, and `Float`.
|
376
384
|
|
377
385
|
```ruby
|
378
|
-
UnitMeasurements::Weight.new(2.25567,
|
386
|
+
UnitMeasurements::Weight.new(2.25567, :kg).to_i
|
379
387
|
#=> 2 kg
|
380
|
-
UnitMeasurements::Weight.new(2.25567,
|
388
|
+
UnitMeasurements::Weight.new(2.25567, :kg).to_f
|
381
389
|
#=> 2.25567 kg
|
382
|
-
UnitMeasurements::Weight.new(2.25567,
|
390
|
+
UnitMeasurements::Weight.new(2.25567, :kg).to_r
|
383
391
|
#=> 225567/100000 kg
|
384
|
-
UnitMeasurements::Weight.new(2.25567,
|
392
|
+
UnitMeasurements::Weight.new(2.25567, :kg).to_d
|
385
393
|
#=> 2.25567 kg
|
386
|
-
UnitMeasurements::Weight.new(2.25567,
|
394
|
+
UnitMeasurements::Weight.new(2.25567, :kg).to_c
|
387
395
|
#=> 2.25567+0i kg
|
388
396
|
```
|
389
397
|
|
@@ -467,41 +475,33 @@ gem "unit_measurements", require: ["unit_measurements/base", "unit_measurements/
|
|
467
475
|
### Building new unit groups
|
468
476
|
|
469
477
|
This library provides simpler way to build your own unit groups. To build new unit group,
|
470
|
-
use `UnitMeasurements.build` in order to define
|
478
|
+
use `UnitMeasurements.build` in order to define units within it:
|
471
479
|
|
472
|
-
If
|
480
|
+
If the unit is supporting [si prefixes](#si-units-support), you can use `si_unit` method to build it.
|
481
|
+
If you build unit using `si_unit`, the unit will be added along with all SI prefixes for it.
|
473
482
|
|
474
483
|
```ruby
|
475
484
|
UnitMeasurements::Time = UnitMeasurements.build do
|
476
|
-
|
477
|
-
base "s", aliases: ["second", "seconds"]
|
478
|
-
|
479
|
-
# Add other units to the group, along with their conversion multipliers against
|
480
|
-
# base unit.
|
481
|
-
unit "min", value: 60.0, aliases: ["minute", "minutes"]
|
485
|
+
unit :s, aliases: [:second, :seconds]
|
482
486
|
|
483
|
-
#
|
484
|
-
|
485
|
-
unit "h", value: "60 min", aliases: ["hour", "hours"]
|
487
|
+
# Add units to the group, along with their conversion multipliers.
|
488
|
+
unit :min, value: "60 s", aliases: [:hour, :hours]
|
486
489
|
|
487
490
|
# You can also specify unit value as an array.
|
488
|
-
unit
|
491
|
+
unit :h, value: [60, :min], aliases: [:day, :days]
|
489
492
|
end
|
490
493
|
```
|
491
494
|
|
492
|
-
If the unit is supporting [si prefixes](#si-units-support), you can use `si_unit` method to build it.
|
493
|
-
If you build unit using `si_unit`, Base unit is automatically added to the group along with all SI prefixes for it.
|
494
|
-
|
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
|
|
504
|
-
All units allow aliases, as long as they are unique. Unit
|
504
|
+
All units allow aliases, as long as they are unique. Unit names can be used to
|
505
505
|
define the unit as long as it is unique. All unit names are case sensitive.
|
506
506
|
|
507
507
|
### Namespaces
|
@@ -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]
|
@@ -32,6 +32,8 @@ module UnitMeasurements
|
|
32
32
|
self.class.new((quantity * conversion_factor), target_unit)
|
33
33
|
end
|
34
34
|
alias_method :to, :convert_to
|
35
|
+
alias_method :in, :convert_to
|
36
|
+
alias_method :as, :convert_to
|
35
37
|
|
36
38
|
def convert_to!(target_unit)
|
37
39
|
measurement = convert_to(target_unit)
|
@@ -40,6 +42,8 @@ module UnitMeasurements
|
|
40
42
|
self
|
41
43
|
end
|
42
44
|
alias_method :to!, :convert_to!
|
45
|
+
alias_method :in!, :convert_to!
|
46
|
+
alias_method :as!, :convert_to!
|
43
47
|
|
44
48
|
def inspect(dump: false)
|
45
49
|
return super() if dump
|
@@ -64,7 +68,7 @@ module UnitMeasurements
|
|
64
68
|
extend Forwardable
|
65
69
|
|
66
70
|
def unit_group
|
67
|
-
raise "`Measurement` does not have a `unit_group` object. You cannot directly use `Measurement`. Instead, build a new unit group by calling `UnitMeasurements.build`."
|
71
|
+
raise BaseError, "`Measurement` does not have a `unit_group` object. You cannot directly use `Measurement`. Instead, build a new unit group by calling `UnitMeasurements.build`."
|
68
72
|
end
|
69
73
|
|
70
74
|
def_delegators :unit_group, :units, :unit_names, :unit_with_name_and_aliases,
|
@@ -78,6 +82,10 @@ module UnitMeasurements
|
|
78
82
|
target ? _parse(source).convert_to(target) : _parse(source)
|
79
83
|
end
|
80
84
|
|
85
|
+
def name
|
86
|
+
to_s.split("::").last.underscore.humanize.downcase
|
87
|
+
end
|
88
|
+
|
81
89
|
private
|
82
90
|
|
83
91
|
def _parse(string)
|
@@ -10,10 +10,6 @@ module UnitMeasurements
|
|
10
10
|
@units = []
|
11
11
|
end
|
12
12
|
|
13
|
-
def base(name, aliases: [])
|
14
|
-
@units << build_unit(name, value: 1.0, aliases: aliases)
|
15
|
-
end
|
16
|
-
|
17
13
|
def unit(name, value: 1.0, aliases: [])
|
18
14
|
@units << build_unit(name, value: value, aliases: aliases)
|
19
15
|
end
|
@@ -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
|
-
|
6
|
+
unit :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
|
-
|
6
|
+
unit :"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 "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"]
|
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 "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"]
|
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: [Rational(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: [Rational(1, 60), :deg], aliases: [:′, :amin, :arcminute, :arcminutes] # ((π / 180) / 60) rad
|
17
|
+
unit :arcsec, value: [Rational(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
|
-
|
6
|
+
unit :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
|
-
si_unit
|
6
|
+
si_unit :K, aliases: [:kelvin, :kelvins]
|
7
7
|
|
8
|
-
unit
|
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
|
data/unit_measurements.gemspec
CHANGED
data/units.md
CHANGED
@@ -4,8 +4,7 @@ As there are lots of units bundled with `unit_measurements`, we recommend you to
|
|
4
4
|
bundled units before converting your measurements.
|
5
5
|
|
6
6
|
**Notes:**
|
7
|
-
1.
|
8
|
-
2. Unit names suffixed with `*` support all [SI prefixes](README.md#si-units-support).
|
7
|
+
1. Unit names suffixed with `*` support all [SI prefixes](README.md#si-units-support).
|
9
8
|
|
10
9
|
Below are the units which are bundled in the unit_measurements.
|
11
10
|
|
@@ -15,7 +14,7 @@ These units are defined in `UnitMeasurements::Length`.
|
|
15
14
|
|
16
15
|
| # | Name | Aliases |
|
17
16
|
|:--|:--|:--|
|
18
|
-
|
|
17
|
+
| 1 | m* | meter, metre, meters, metres |
|
19
18
|
| 2 | in | ", inch, inches |
|
20
19
|
| 3 | ft | ', foot, feet |
|
21
20
|
| 4 | yd | yard, yards |
|
@@ -27,7 +26,7 @@ These units are defined in `UnitMeasurements::Weight`.
|
|
27
26
|
|
28
27
|
| # | Name | Aliases |
|
29
28
|
|--|--|--|
|
30
|
-
|
|
29
|
+
| 1 | g* | gram, grams, gramme, grammes |
|
31
30
|
| 2 | q | quintal, quintals |
|
32
31
|
| 3 | t | tonne, tonnes, metric tonne, metric tonnes |
|
33
32
|
|
@@ -37,7 +36,7 @@ These units are defined in `UnitMeasurements::Time`.
|
|
37
36
|
|
38
37
|
| # | Name | Aliases |
|
39
38
|
|:--|:--|:--|
|
40
|
-
|
|
39
|
+
| 1 | s* | sec, second, seconds |
|
41
40
|
| 2 | h | hr, hour, hours |
|
42
41
|
| 3 | d | day, days |
|
43
42
|
| 4 | wk | week, weeks |
|
@@ -55,7 +54,7 @@ These units are defined in `UnitMeasurements::AmountOfSubstance`.
|
|
55
54
|
|
56
55
|
| # | Name | Aliases |
|
57
56
|
|:--|:--|:--|
|
58
|
-
|
|
57
|
+
| 1 | mol* | mole, moles |
|
59
58
|
| 2 | NA | avogadro constant |
|
60
59
|
|
61
60
|
## 5. Electric current
|
@@ -64,7 +63,7 @@ These units are defined in `UnitMeasurements::ElectricCurrent`.
|
|
64
63
|
|
65
64
|
| # | Name | Aliases |
|
66
65
|
|:--|:--|:--|
|
67
|
-
|
|
66
|
+
| 1 | A* | amp, ampere, amperes |
|
68
67
|
| 2 | abA | abampere, abamperes |
|
69
68
|
| 3 | Bi | biot, biots |
|
70
69
|
| 4 | statA | statampere, statamperes |
|
@@ -75,7 +74,7 @@ These units are defined in `UnitMeasurements::LuminousIntensity`.
|
|
75
74
|
|
76
75
|
| # | Name | Aliases |
|
77
76
|
|:--|:--|:--|
|
78
|
-
|
|
77
|
+
| 1 | cd* | candela, candelas |
|
79
78
|
| 2 | hk | hefnerkerze |
|
80
79
|
|
81
80
|
## 7. Temperature
|
@@ -84,7 +83,7 @@ These units are defined in `UnitMeasurements::Temperature`.
|
|
84
83
|
|
85
84
|
| # | Name | Aliases |
|
86
85
|
|:--|:--|:--|
|
87
|
-
|
|
86
|
+
| 1 | K* | kelvin, kelvins |
|
88
87
|
| 2 | °R | R, °Ra, Ra, rankine |
|
89
88
|
|
90
89
|
## 8. Area
|
@@ -93,7 +92,7 @@ These units are defined in `UnitMeasurements::Area`.
|
|
93
92
|
|
94
93
|
| # | Name | Aliases |
|
95
94
|
|:--|:--|:--|
|
96
|
-
|
|
95
|
+
| 1 | m² | m^2, sq m, square meter, square meters, square metre, square metres |
|
97
96
|
| 2 | km² | km^2, sq km, square kilometer, square kilometers, square kilometre, square kilometres |
|
98
97
|
| 3 | in² | in^2, sq in, square inch, square inches |
|
99
98
|
| 4 | ft² | ft^2, sq ft, square foot, square feet |
|
@@ -106,7 +105,7 @@ These units are defined in `UnitMeasurements::Volume`.
|
|
106
105
|
|
107
106
|
| # | Name | Aliases |
|
108
107
|
|:--|:--|:--|
|
109
|
-
|
|
108
|
+
| 1 | l* | liter, litre, liters, litres |
|
110
109
|
| 2 | m³ | m^3, cu m, cubic meter, cubic meters, cubic metre, cubic metres |
|
111
110
|
| 3 | mm³ | mm^3, cu mm, cubic millimeter, cubic millimeters, cubic millimetre, cubic millimetres |
|
112
111
|
| 4 | cm³ | cm^3, cu cm, cubic centimeter, cubic centimeters, cubic centimetre, cubic centimetres |
|
@@ -123,7 +122,7 @@ These units are defined in `UnitMeasurements::Density`.
|
|
123
122
|
|
124
123
|
| # | Name | Aliases |
|
125
124
|
|:--|:--|:--|
|
126
|
-
|
|
125
|
+
| 1 | g/m³ | g/m^3, g·m⁻³, gram per cubic meter, grams per cubic meter, gramme per cubic metre, grammes per cubic metre |
|
127
126
|
| 2 | kg/m³ | kg/m^3, kg·m⁻³, kilogram per cubic meter, kilograms per cubic meter, kilogramme per cubic metre, kilogrammes per cubic metre |
|
128
127
|
| 3 | g/l | g·l⁻¹, gram per liter, grams per liter, gramme per litre, grammes per litre |
|
129
128
|
| 4 | g/ml | g·ml⁻¹, gram per milliliter, grams per milliliter, gramme per millilitre, grammes per millilitre |
|
@@ -135,7 +134,7 @@ These units are defined in `UnitMeasurements::Quantity`.
|
|
135
134
|
|
136
135
|
| # | Name | Aliases |
|
137
136
|
|:--|:--|:--|
|
138
|
-
|
|
137
|
+
| 1 | pc | pcs, piece, pieces |
|
139
138
|
| 2 | pr | pair, pairs |
|
140
139
|
| 3 | gr | gross, grosses |
|
141
140
|
| 4 | dz | doz, dozen, dozens |
|
@@ -147,7 +146,7 @@ These units are defined in `UnitMeasurements::SoundLevel`.
|
|
147
146
|
|
148
147
|
| # | Name | Aliases |
|
149
148
|
|:--|:--|:--|
|
150
|
-
|
|
149
|
+
| 1 | B* | bel, bels |
|
151
150
|
| 2 | Np | neper, nepers |
|
152
151
|
|
153
152
|
## 13. Plane angle
|
@@ -156,7 +155,7 @@ These units are defined in `UnitMeasurements::PlaneAngle`.
|
|
156
155
|
|
157
156
|
| # | Name | Aliases |
|
158
157
|
|:--|:--|:--|
|
159
|
-
|
|
158
|
+
| 1 | rad* | radian, radians |
|
160
159
|
| 2 | deg | °, degree, degrees |
|
161
160
|
| 3 | gon | ᵍ, grad, gradian, gradians |
|
162
161
|
| 4 | cir | circle, circles |
|
@@ -172,7 +171,7 @@ These units are defined in `UnitMeasurements::SolidAngle`.
|
|
172
171
|
|
173
172
|
| # | Name | Aliases |
|
174
173
|
|:--|:--|:--|
|
175
|
-
|
|
174
|
+
| 1 | sr* | steradian, steradians |
|
176
175
|
| 2 | sp | spat, spats |
|
177
176
|
| 3 | deg² | (°)², sq °, square degree, square degrees |
|
178
177
|
| 4 | arcmin² | (′)², sq ′, square arcminute, square arcminutes |
|
@@ -184,7 +183,7 @@ These units are defined in `UnitMeasurements::Force`.
|
|
184
183
|
|
185
184
|
| # | Name | Aliases |
|
186
185
|
|:--|:--|:--|
|
187
|
-
|
|
186
|
+
| 1 | N* | newton, newtons |
|
188
187
|
| 2 | tf | tonne-force |
|
189
188
|
| 3 | dyn | dyne, dynes |
|
190
189
|
| 4 | kgf | kilogram-force, kilogramme-force |
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unit_measurements
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harshal LADHE
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -99,7 +99,7 @@ files:
|
|
99
99
|
- CHANGELOG.md
|
100
100
|
- Gemfile
|
101
101
|
- Gemfile.lock
|
102
|
-
- LICENSE
|
102
|
+
- LICENSE.md
|
103
103
|
- README.md
|
104
104
|
- Rakefile
|
105
105
|
- lib/unit_measurements.rb
|