unit_measurements 5.11.1 → 5.12.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 +13 -0
- data/Gemfile.lock +1 -1
- data/lib/unit_measurements/arithmetic.rb +5 -0
- data/lib/unit_measurements/base.rb +6 -2
- data/lib/unit_measurements/errors/missing_primitive_unit_error.rb +24 -0
- data/lib/unit_measurements/measurement.rb +8 -2
- data/lib/unit_measurements/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e01978467f274548e8cf792d9b7bfe26ab85155a2c099482cb8b4017641ed900
|
4
|
+
data.tar.gz: d09990112a19291527059e822906a802a051541b654babad13e97110c5557dea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0faa94f0a962f19134ff58276c6c876a30a81817172039c4261eaa9a15eeb61dd7047f61b96168c2115c4ba40711fee42cb4ceb832c6e6640bd9c8e7e0f4343b
|
7
|
+
data.tar.gz: d9213995299feeb51dda98cc4dbbd3bd76f6c4782a8e04b9612cc7f3134b192c74aa80b027779c1b8c862358a84a8c40469753a086ceb94fd5b5ee2b8d33e973
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
## [5.12.0](https://github.com/shivam091/unit_measurements/compare/v5.11.1...v5.12.0) - 2023-11-25
|
2
|
+
|
3
|
+
### What's new
|
4
|
+
|
5
|
+
- Added `MissingPrimitiveUnitError` error if user tries to convert measurement to
|
6
|
+
the primitive unit but it's not set for the unit group.
|
7
|
+
- Aliased `#+` method as `#add`.
|
8
|
+
- Aliased `#-` method as `#subtract`.
|
9
|
+
- Aliased `#*` method as `#times` and `#multiply`.
|
10
|
+
- Aliased `#/` method as `#divide`.
|
11
|
+
|
12
|
+
----------
|
13
|
+
|
1
14
|
## [5.11.1](https://github.com/shivam091/unit_measurements/compare/v5.11.0...v5.11.1) - 2023-11-16
|
2
15
|
|
3
16
|
### What's changed
|
data/Gemfile.lock
CHANGED
@@ -41,6 +41,7 @@ module UnitMeasurements
|
|
41
41
|
def +(other)
|
42
42
|
arithmetic_operation(other, :+)
|
43
43
|
end
|
44
|
+
alias_method :add, :+
|
44
45
|
|
45
46
|
# Subtracts the quantity of the other measurement or a numeric value from the
|
46
47
|
# quantity of the current measurement.
|
@@ -62,6 +63,7 @@ module UnitMeasurements
|
|
62
63
|
def -(other)
|
63
64
|
arithmetic_operation(other, :-)
|
64
65
|
end
|
66
|
+
alias_method :subtract, :-
|
65
67
|
|
66
68
|
# Multiplies the quantity of the current measurement by the quantity of the
|
67
69
|
# other measurement or a numeric value.
|
@@ -84,6 +86,8 @@ module UnitMeasurements
|
|
84
86
|
arithmetic_operation(other, :*)
|
85
87
|
end
|
86
88
|
alias_method :scale, :*
|
89
|
+
alias_method :times, :*
|
90
|
+
alias_method :multiply, :*
|
87
91
|
|
88
92
|
# Divides the quantity of the current measurement by the quantity of the other
|
89
93
|
# measurement or a numeric value.
|
@@ -105,6 +109,7 @@ module UnitMeasurements
|
|
105
109
|
def /(other)
|
106
110
|
arithmetic_operation(other, :/)
|
107
111
|
end
|
112
|
+
alias_method :divide, :/
|
108
113
|
|
109
114
|
# Raises the quantity of the current measurement to the power of the quantity of
|
110
115
|
# the other measurement or numeric value.
|
@@ -16,10 +16,13 @@ require "unit_measurements/version"
|
|
16
16
|
module UnitMeasurements
|
17
17
|
# This is the base class for custom errors in the +UnitMeasurements+ module.
|
18
18
|
#
|
19
|
+
# @see UnitError
|
19
20
|
# @see ParseError
|
20
|
-
# @see
|
21
|
+
# @see BlankUnitError
|
22
|
+
# @see BlankQuantityError
|
21
23
|
# @see UnitAlreadyDefinedError
|
22
|
-
# @see
|
24
|
+
# @see MissingPrimitiveUnitError
|
25
|
+
# @see PrimitiveUnitAlreadySetError
|
23
26
|
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
24
27
|
# @since 1.1.0
|
25
28
|
class BaseError < StandardError; end
|
@@ -168,3 +171,4 @@ require "unit_measurements/errors/unit_already_defined_error"
|
|
168
171
|
require "unit_measurements/errors/primitive_unit_already_set_error"
|
169
172
|
require "unit_measurements/errors/blank_quantity_error"
|
170
173
|
require "unit_measurements/errors/blank_unit_error"
|
174
|
+
require "unit_measurements/errors/missing_primitive_unit_error"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module UnitMeasurements
|
6
|
+
# The +UnitMeasurements::MissingPrimitiveUnitError+ class represents an error
|
7
|
+
# that occurs when the primitive unit is not set for a unit group.
|
8
|
+
#
|
9
|
+
# This error is raised when a user attempts to convert a measurement to the
|
10
|
+
# primitive unit of a unit group that does not have a primitive unit defined.
|
11
|
+
#
|
12
|
+
# @see BaseError
|
13
|
+
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
14
|
+
# @since 5.12.0
|
15
|
+
class MissingPrimitiveUnitError < BaseError
|
16
|
+
# Initializes a new +MissingPrimitiveUnitError+ instance.
|
17
|
+
#
|
18
|
+
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
19
|
+
# @since 5.12.0
|
20
|
+
def initialize
|
21
|
+
super("The primitive unit is not set for the unit group.")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -147,11 +147,17 @@ module UnitMeasurements
|
|
147
147
|
# A new +Measurement+ instance with the converted +quantity+ and
|
148
148
|
# +target unit+.
|
149
149
|
#
|
150
|
+
# @raise [MissingPrimitiveUnitError]
|
151
|
+
# if primitive unit is not set for the unit group.
|
152
|
+
#
|
150
153
|
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
151
154
|
# @since 1.0.0
|
152
155
|
def convert_to(target_unit, use_cache: false)
|
153
156
|
target_unit = if target_unit.to_s.eql?("primitive")
|
154
|
-
self.class.
|
157
|
+
primitive_unit = self.class.primitive
|
158
|
+
|
159
|
+
raise MissingPrimitiveUnitError if primitive_unit.nil?
|
160
|
+
primitive_unit
|
155
161
|
else
|
156
162
|
unit_from_unit_or_name!(target_unit)
|
157
163
|
end
|
@@ -474,7 +480,7 @@ module UnitMeasurements
|
|
474
480
|
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
475
481
|
# @since 1.0.0
|
476
482
|
def unit_from_unit_or_name!(value)
|
477
|
-
value.is_a?(Unit) ? value : self.class.
|
483
|
+
value.is_a?(Unit) ? value : self.class.unit_for!(value)
|
478
484
|
end
|
479
485
|
|
480
486
|
# Calculates the conversion factor between the current unit and the target
|
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: 5.
|
4
|
+
version: 5.12.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-11-
|
11
|
+
date: 2023-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/unit_measurements/conversion.rb
|
114
114
|
- lib/unit_measurements/errors/blank_quantity_error.rb
|
115
115
|
- lib/unit_measurements/errors/blank_unit_error.rb
|
116
|
+
- lib/unit_measurements/errors/missing_primitive_unit_error.rb
|
116
117
|
- lib/unit_measurements/errors/parse_error.rb
|
117
118
|
- lib/unit_measurements/errors/primitive_unit_already_set_error.rb
|
118
119
|
- lib/unit_measurements/errors/unit_already_defined_error.rb
|