unit_measurements 1.6.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -3
- data/Gemfile.lock +1 -1
- data/README.md +18 -0
- data/lib/unit_measurements/base.rb +1 -0
- data/lib/unit_measurements/conversion.rb +62 -0
- data/lib/unit_measurements/measurement.rb +1 -0
- data/lib/unit_measurements/unit_groups/all.rb +2 -0
- data/lib/unit_measurements/unit_groups/amount_of_substance.rb +9 -0
- data/lib/unit_measurements/unit_groups/time.rb +18 -0
- data/lib/unit_measurements/version.rb +1 -1
- data/units.md +27 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8601bdbb7fb37856840869d267729adefddbf714ab6696376d6165252f9531f3
|
4
|
+
data.tar.gz: 33c504c31db58c752ecb4b587112ae2df4b0af6c0e1efd957af1202e635e3622
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 119bd53409c40aac1242b0721e3737e65231a2e243e1e0151ede230b5b2f76358679a63a0b9fc66c8ec8bf5fda9b9395a8539c8ad2f6fd08933edc8717ffaa6d
|
7
|
+
data.tar.gz: 3a5ed9b00ec6e5abee27bc8fd653e5c8c069ad18c5c5cac2c4dbcba519f1c72cbd574243f8c5e955fb4a896a737434b376395b2b4a46e114e40b473292fe04b8
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,24 @@
|
|
1
|
+
## [2.1.0](https://github.com/shivam091/unit_measurements/compare/v1.7.0...v2.1.0) - 2023-08-21
|
2
|
+
|
3
|
+
### What's new
|
4
|
+
|
5
|
+
- Added unit group for `time` units.
|
6
|
+
- Added unit group for `amount of substance` units.
|
7
|
+
|
8
|
+
----------
|
9
|
+
|
10
|
+
## [1.7.0](https://github.com/shivam091/unit_measurements/compare/v1.6.0...v1.7.0) - 2023-08-20
|
11
|
+
|
12
|
+
### What's new
|
13
|
+
|
14
|
+
- Added support to convert the measurements to other numeric types viz.,
|
15
|
+
`Integer`, `BigDecimal`, `Rational`, `Complex`, and `Float`.
|
16
|
+
|
17
|
+
----------
|
18
|
+
|
1
19
|
## [1.6.0](https://github.com/shivam091/unit_measurements/compare/v1.5.1...v1.6.0) - 2023-08-19
|
2
20
|
|
3
|
-
|
21
|
+
### What's new
|
4
22
|
|
5
23
|
- Added support to perform mathematical operations on the measurements.
|
6
24
|
|
@@ -67,10 +85,10 @@
|
|
67
85
|
|
68
86
|
----------
|
69
87
|
|
70
|
-
##
|
88
|
+
## 0.1.0 - 2023-09-13
|
71
89
|
|
72
90
|
### Initial release
|
73
91
|
|
74
92
|
-----------
|
75
93
|
|
76
|
-
|
94
|
+
### Unreleased
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -369,6 +369,24 @@ UnitMeasurements::Length.new(17.625, :m).ceil
|
|
369
369
|
#=> 18 m
|
370
370
|
```
|
371
371
|
|
372
|
+
### Conversions
|
373
|
+
|
374
|
+
You can convert measurement quantity directly to other numeric types viz.
|
375
|
+
`Integer`, `BigDecimal`, `Rational`, `Complex`, and `Float`.
|
376
|
+
|
377
|
+
```ruby
|
378
|
+
UnitMeasurements::Weight.new(2.25567, :kg).to_i
|
379
|
+
#=> 2 kg
|
380
|
+
UnitMeasurements::Weight.new(2.25567, :kg).to_f
|
381
|
+
#=> 2.25567 kg
|
382
|
+
UnitMeasurements::Weight.new(2.25567, :kg).to_r
|
383
|
+
#=> 225567/100000 kg
|
384
|
+
UnitMeasurements::Weight.new(2.25567, :kg).to_d
|
385
|
+
#=> 2.25567 kg
|
386
|
+
UnitMeasurements::Weight.new(2.25567, :kg).to_c
|
387
|
+
#=> 2.25567+0i kg
|
388
|
+
```
|
389
|
+
|
372
390
|
## Units
|
373
391
|
|
374
392
|
The **`UnitMeasurements::Unit`** class is used to represent the units for a measurement.
|
@@ -27,6 +27,7 @@ require "unit_measurements/unit"
|
|
27
27
|
require "unit_measurements/unit_group"
|
28
28
|
require "unit_measurements/arithmetic"
|
29
29
|
require "unit_measurements/comparison"
|
30
|
+
require "unit_measurements/conversion"
|
30
31
|
require "unit_measurements/math"
|
31
32
|
require "unit_measurements/normalizer"
|
32
33
|
require "unit_measurements/parser"
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module UnitMeasurements
|
6
|
+
module Conversion
|
7
|
+
# Converts quantity of the measurement to +Integer+.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# UnitMeasurements::Weight.new(2.25567, :kg).to_i
|
11
|
+
# => 2 kg
|
12
|
+
#
|
13
|
+
# @return [Measurement]
|
14
|
+
def to_i
|
15
|
+
self.class.new(quantity.to_i, unit)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Converts quantity of the measurement to +Float+.
|
19
|
+
#
|
20
|
+
# @example
|
21
|
+
# UnitMeasurements::Weight.new(2.25567, :kg).to_f
|
22
|
+
# => 2.25567 kg
|
23
|
+
#
|
24
|
+
# @return [Measurement]
|
25
|
+
def to_f
|
26
|
+
self.class.new(quantity.to_f, unit)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Converts quantity of the measurement to +Rational+.
|
30
|
+
#
|
31
|
+
# @example
|
32
|
+
# UnitMeasurements::Weight.new(2.25567, :kg).to_r
|
33
|
+
# => 225567/100000 kg
|
34
|
+
#
|
35
|
+
# @return [Measurement]
|
36
|
+
def to_r
|
37
|
+
self.class.new(quantity.to_r, unit)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Converts quantity of the measurement to +Complex+.
|
41
|
+
#
|
42
|
+
# @example
|
43
|
+
# UnitMeasurements::Weight.new(2.25567, :kg).to_c
|
44
|
+
# => 2.25567+0i kg
|
45
|
+
#
|
46
|
+
# @return [Measurement]
|
47
|
+
def to_c
|
48
|
+
self.class.new(quantity.to_c, unit)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Converts quantity of the measurement to +BigDecimal+.
|
52
|
+
#
|
53
|
+
# @example
|
54
|
+
# UnitMeasurements::Weight.new(2.25567, :kg).to_d
|
55
|
+
# => 2.25567 kg
|
56
|
+
#
|
57
|
+
# @return [Measurement]
|
58
|
+
def to_d
|
59
|
+
self.class.new(quantity.to_d, unit)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
UnitMeasurements::AmountOfSubstance = UnitMeasurements.build do
|
6
|
+
si_unit :mol, aliases: [:mole, :moles]
|
7
|
+
|
8
|
+
unit :NA, value: "1.6605389210322e-24 mol", aliases: [:"avogadro constant"]
|
9
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
UnitMeasurements::Time = UnitMeasurements.build do
|
6
|
+
si_unit :s, aliases: [:sec, :second, :seconds]
|
7
|
+
|
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
|
+
end
|
data/units.md
CHANGED
@@ -30,3 +30,30 @@ These units are defined in `UnitMeasurements::Weight`.
|
|
30
30
|
| **1** | **g\*** | **gram, grams, gramme, grammes** |
|
31
31
|
| 2 | q | quintal, quintals |
|
32
32
|
| 3 | t | tonne, tonnes, metric tonne, metric tonnes |
|
33
|
+
|
34
|
+
## 3. Time
|
35
|
+
|
36
|
+
These units are defined in `UnitMeasurements::Time`.
|
37
|
+
|
38
|
+
| # | Name | Aliases |
|
39
|
+
|:--|:--|:--|
|
40
|
+
| **1** | **s\*** | **sec, second, seconds** |
|
41
|
+
| 2 | h | hr, hour, hours |
|
42
|
+
| 3 | d | day, days |
|
43
|
+
| 4 | wk | week, weeks |
|
44
|
+
| 5 | fn | 4tnite, fortnight, fortnights |
|
45
|
+
| 6 | mo | month, months |
|
46
|
+
| 7 | yr | y, year, years |
|
47
|
+
| 8 | min | minute, minutes |
|
48
|
+
| 9 | qtr | quarter, quarters |
|
49
|
+
| 10 | dec | decade, decades |
|
50
|
+
| 11 | cent | century, centuries |
|
51
|
+
|
52
|
+
## 4. Amount of substance
|
53
|
+
|
54
|
+
These units are defined in `UnitMeasurements::AmountOfSubstance`.
|
55
|
+
|
56
|
+
| # | Symbol | Aliases |
|
57
|
+
|:--|:--|:--|
|
58
|
+
| **1** | **mol\*** | **mole, moles** |
|
59
|
+
| 2 | NA | avogadro constant |
|
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: 1.
|
4
|
+
version: 2.1.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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/unit_measurements/arithmetic.rb
|
107
107
|
- lib/unit_measurements/base.rb
|
108
108
|
- lib/unit_measurements/comparison.rb
|
109
|
+
- lib/unit_measurements/conversion.rb
|
109
110
|
- lib/unit_measurements/errors/parse_error.rb
|
110
111
|
- lib/unit_measurements/errors/unit_already_defined_error.rb
|
111
112
|
- lib/unit_measurements/errors/unit_error.rb
|
@@ -118,7 +119,9 @@ files:
|
|
118
119
|
- lib/unit_measurements/unit_group.rb
|
119
120
|
- lib/unit_measurements/unit_group_builder.rb
|
120
121
|
- lib/unit_measurements/unit_groups/all.rb
|
122
|
+
- lib/unit_measurements/unit_groups/amount_of_substance.rb
|
121
123
|
- lib/unit_measurements/unit_groups/length.rb
|
124
|
+
- lib/unit_measurements/unit_groups/time.rb
|
122
125
|
- lib/unit_measurements/unit_groups/weight.rb
|
123
126
|
- lib/unit_measurements/version.rb
|
124
127
|
- unit_measurements.gemspec
|