unit_measurements 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -2
- data/Gemfile.lock +1 -1
- data/README.md +4 -1
- data/lib/unit_measurements/arithmetic.rb +1 -0
- data/lib/unit_measurements/errors/parse_error.rb +1 -0
- data/lib/unit_measurements/errors/unit_already_defined_error.rb +1 -0
- data/lib/unit_measurements/errors/unit_error.rb +1 -0
- data/lib/unit_measurements/formatter.rb +1 -0
- data/lib/unit_measurements/measurement.rb +5 -0
- data/lib/unit_measurements/unit_group_builder.rb +3 -0
- 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: aac3030ed1c46bb4bdfe831bc9bedb29ad2a8b0e28595ba4726b2a3ff5e24791
|
4
|
+
data.tar.gz: 9179c7b41ef7e84b6864ef98ccb45210ab34b2488830aa3de5552659b7f39039
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5435fba092be97c1c8407b917857c1990db07d1aa1729653ecf14519d98dcec2a4c5e5ad0c4997586eb2f72b17d1099506068aa99eb592ee35ddd8da4a2f8ba7
|
7
|
+
data.tar.gz: 5938944868b729168d49d1f5e7e888029931bb17237fd72c66980bf6b47d7fe58f8eefdd94f1927652d9b5d1e3e480e8df746f5c7607995390ea7caeec186634
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,16 @@
|
|
1
|
+
## [1.5.1](https://github.com/shivam091/unit_measurements/compare/v1.5.0...v1.5.1) - 2023-08-18
|
2
|
+
|
3
|
+
### What's updated
|
4
|
+
|
5
|
+
- Added extra blank line between method code and last code statement (considered as return).
|
6
|
+
|
7
|
+
----------
|
8
|
+
|
1
9
|
## [1.5.0](https://github.com/shivam091/unit_measurements/compare/v1.4.0...v1.5.0) - 2023-08-18
|
2
10
|
|
3
|
-
|
11
|
+
### What's fixed
|
4
12
|
|
5
|
-
- Fixed precision in `Measurement#quantity` method
|
13
|
+
- Fixed precision in `Measurement#quantity` method.
|
6
14
|
|
7
15
|
----------
|
8
16
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -307,7 +307,6 @@ UnitMeasurements::Weight.unit_or_alias?(:gramme)
|
|
307
307
|
|
308
308
|
You have ability to compare the measurements with the same or different units within the same unit group.
|
309
309
|
For example, comparing weight with weight will work, comparing a weight with a area would fail.
|
310
|
-
Allowed comparisons are `==`, `!=`, `>`, `>=`, `<`, and `<=`.
|
311
310
|
|
312
311
|
```ruby
|
313
312
|
UnitMeasurements::Weight.new(1, "kg") == UnitMeasurements::Weight.new(1, :kg)
|
@@ -320,6 +319,10 @@ UnitMeasurements::Weight.parse("1 kg") <= UnitMeasurements::Weight.parse("0.5 kg
|
|
320
319
|
#=> false
|
321
320
|
UnitMeasurements::Weight.parse("1 kg") >= UnitMeasurements::Weight.parse("0.5 kg")
|
322
321
|
#=> true
|
322
|
+
UnitMeasurements::Length.new(1, :ft).between?(UnitMeasurements::Length.new(12, :in), UnitMeasurements::Length.new(24, :in))
|
323
|
+
#=> true
|
324
|
+
UnitMeasurements::Length.new(1, :ft).clamp(UnitMeasurements::Length.new(13, :in), UnitMeasurements::Length.new(24, :in))
|
325
|
+
#=> 13 in
|
323
326
|
```
|
324
327
|
|
325
328
|
### Arithmetic
|
@@ -26,6 +26,7 @@ module UnitMeasurements
|
|
26
26
|
return self if target_unit == unit
|
27
27
|
|
28
28
|
conversion_factor = (unit.conversion_factor / target_unit.conversion_factor)
|
29
|
+
|
29
30
|
self.class.new((quantity * conversion_factor), target_unit)
|
30
31
|
end
|
31
32
|
alias_method :to, :convert_to
|
@@ -33,6 +34,7 @@ module UnitMeasurements
|
|
33
34
|
def convert_to!(target_unit)
|
34
35
|
measurement = convert_to(target_unit)
|
35
36
|
@quantity, @unit = measurement.quantity, measurement.unit
|
37
|
+
|
36
38
|
self
|
37
39
|
end
|
38
40
|
alias_method :to!, :convert_to!
|
@@ -70,6 +72,7 @@ module UnitMeasurements
|
|
70
72
|
def parse(input)
|
71
73
|
input = Normalizer.normalize(input)
|
72
74
|
source, target = input.match(CONVERSION_STRING_REGEXP)&.captures
|
75
|
+
|
73
76
|
target ? _parse(source).convert_to(target) : _parse(source)
|
74
77
|
end
|
75
78
|
|
@@ -77,6 +80,7 @@ module UnitMeasurements
|
|
77
80
|
|
78
81
|
def _parse(string)
|
79
82
|
quantity, unit = Parser.parse(string)
|
83
|
+
|
80
84
|
new(quantity, unit)
|
81
85
|
end
|
82
86
|
end
|
@@ -92,6 +96,7 @@ module UnitMeasurements
|
|
92
96
|
when String
|
93
97
|
quantity = Normalizer.normalize(quantity)
|
94
98
|
quantity, _ = Parser.parse(quantity)
|
99
|
+
|
95
100
|
quantity
|
96
101
|
else
|
97
102
|
quantity
|
@@ -37,17 +37,20 @@ module UnitMeasurements
|
|
37
37
|
end
|
38
38
|
si_units << build_unit("#{short_prefix}#{name}", value: "#{multiplier} #{name}", aliases: si_aliases)
|
39
39
|
end
|
40
|
+
|
40
41
|
si_units
|
41
42
|
end
|
42
43
|
|
43
44
|
def build_unit(name, value:, aliases:)
|
44
45
|
unit = Unit.new(name, value: value, aliases: aliases)
|
45
46
|
check_for_duplicate_unit_names!(unit)
|
47
|
+
|
46
48
|
unit
|
47
49
|
end
|
48
50
|
|
49
51
|
def check_for_duplicate_unit_names!(unit)
|
50
52
|
names = @units.flat_map(&:names)
|
53
|
+
|
51
54
|
if names.any? { |name| unit.names.include?(name) }
|
52
55
|
raise UnitAlreadyDefinedError.new(unit.name)
|
53
56
|
end
|