unit_measurements 5.0.0 → 5.1.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/.github/workflows/pages.yml +1 -1
- data/.yardopts +2 -0
- data/CHANGELOG.md +24 -0
- data/Gemfile.lock +1 -1
- data/README.md +19 -49
- data/lib/unit_measurements/arithmetic.rb +70 -0
- data/lib/unit_measurements/errors/parse_error.rb +2 -0
- data/lib/unit_measurements/errors/unit_already_defined_error.rb +2 -0
- data/lib/unit_measurements/errors/unit_error.rb +2 -0
- data/lib/unit_measurements/measurement.rb +28 -2
- data/lib/unit_measurements/unit.rb +12 -3
- data/lib/unit_measurements/unit_group.rb +5 -2
- data/lib/unit_measurements/unit_group_builder.rb +3 -1
- 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: 0a5ba942c1c99f76efc0db51ce916d31d199646d5bd2a5ace71b34fadbadacb2
|
4
|
+
data.tar.gz: 681c3ce17cebe41d715c78b25669afe6347d726405b4fcea74ffd8da3d5e9dc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 518cdb270f00447a0a7817e4db3bf8dbd83e6ed1ccdb82e58ef60579d774eff9f40544669b216ab42ee7133e23cf69f1ce149c7d051e8ffc3e147cc356361392
|
7
|
+
data.tar.gz: 239e100a9b733cbe1792ffc54c812a5fce1abecc2e449bdd03ee6215b84e72ad98eaaa1abec9d9e389deee515fef04cdef022e7c8fe6ab765c8b436eb4f0b0b2
|
data/.github/workflows/pages.yml
CHANGED
data/.yardopts
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
## [5.1.1](https://github.com/shivam091/unit_measurements/compare/v5.1.0...v5.1.1) - 2023-10-20
|
2
|
+
|
3
|
+
### What's updated
|
4
|
+
|
5
|
+
- Updated readme and documentation.
|
6
|
+
- Updated documentation hosting link to `https://shivam091.github.io/unit_measurements`.
|
7
|
+
|
8
|
+
----------
|
9
|
+
|
10
|
+
## [5.1.0](https://github.com/shivam091/unit_measurements/compare/v5.0.0...v5.1.0) - 2023-10-19
|
11
|
+
|
12
|
+
### What's new
|
13
|
+
|
14
|
+
- Added new methods (`**`, `-@`, `nonzero?`, `zero?`, `positive?`, `negative?`,
|
15
|
+
`finite?`, and `infinite?`) to perform arithmetic operations.
|
16
|
+
- Added new alias `scale` for `**` arithmetic method.
|
17
|
+
|
18
|
+
### What's updated
|
19
|
+
|
20
|
+
- Updated readme and documentation.
|
21
|
+
- Updated documentation hosting link to `https://rubydoc.info/gems/unit_measurements`.
|
22
|
+
|
23
|
+
----------
|
24
|
+
|
1
25
|
## [5.0.0](https://github.com/shivam091/unit_measurements/compare/v4.12.0...v5.0.0) - 2023-10-18
|
2
26
|
|
3
27
|
### What's new
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -22,19 +22,19 @@ to numerous errors.
|
|
22
22
|
|
23
23
|
The `unit_measurements` gem is designed to simplify the handling of units for scientific calculations.
|
24
24
|
|
25
|
-
##
|
25
|
+
## Features
|
26
26
|
|
27
|
-
1.
|
28
|
-
2.
|
29
|
-
3.
|
30
|
-
4.
|
31
|
-
5.
|
27
|
+
1. Provides easy conversion between units.
|
28
|
+
2. Lightweight and easily extensible to include other units and conversions.
|
29
|
+
3. Built in support for various [unit groups](https://github.com/shivam091/unit_measurements/blob/main/units.md).
|
30
|
+
4. Well organized and very descriptive documentation published [here](https://shivam091.github.io/unit_measurements).
|
31
|
+
5. Parses strings representing complex, fractional, mixed fractional, scientific numbers, and ratios.
|
32
32
|
|
33
33
|
## Disclaimer
|
34
34
|
|
35
|
-
_The unit conversions
|
36
|
-
While we aim
|
37
|
-
Users are advised to cross-verify conversions
|
35
|
+
_The unit conversions provided here are for reference and general informational
|
36
|
+
purposes. While we aim for accuracy, we cannot guarantee precision in all scenarios.
|
37
|
+
Users are advised to cross-verify conversions for their specific use cases._
|
38
38
|
|
39
39
|
## Minimum Requirements
|
40
40
|
|
@@ -143,14 +143,8 @@ UnitMeasurements::Length.parse("2+3i km to m")
|
|
143
143
|
```ruby
|
144
144
|
UnitMeasurements::Length.parse("2 ½ km").convert_to("m")
|
145
145
|
#=> 2500.0 m
|
146
|
-
UnitMeasurements::Length.parse("2/3 km").convert_to("m")
|
147
|
-
#=> 666.666666666667 m
|
148
146
|
UnitMeasurements::Length.parse("2/3 km to m")
|
149
147
|
#=> 666.666666666667 m
|
150
|
-
UnitMeasurements::Length.parse("2 1/2 km").convert_to("m")
|
151
|
-
#=> 2500.0 m
|
152
|
-
UnitMeasurements::Length.parse("2 ½ km to m")
|
153
|
-
#=> 2500.0 m
|
154
148
|
```
|
155
149
|
|
156
150
|
You can check supported special characters for fractional notations
|
@@ -159,8 +153,6 @@ You can check supported special characters for fractional notations
|
|
159
153
|
**Parse ratios, source unit, and (or) target unit:**
|
160
154
|
|
161
155
|
```ruby
|
162
|
-
UnitMeasurements::Length.new("1:2", "km").convert_to("m")
|
163
|
-
#=> 500.0 m
|
164
156
|
UnitMeasurements::Length.parse("1:2 km").convert_to("m")
|
165
157
|
#=> 500.0 m
|
166
158
|
UnitMeasurements::Length.parse("1:2 km to m")
|
@@ -173,12 +165,8 @@ If you want to format measurement to certain format, you can use `#format` metho
|
|
173
165
|
If format is not specified, it defaults to `"%.2<value>f %<unit>s"`.
|
174
166
|
|
175
167
|
```ruby
|
176
|
-
UnitMeasurements::Length.new(100, "m").to("in").format
|
177
|
-
#=> "3937.01 in"
|
178
168
|
UnitMeasurements::Length.new(100, "m").to("in").format("%.4<quantity>f %<unit>s")
|
179
169
|
#=> "3937.0079 in"
|
180
|
-
UnitMeasurements::Length.new(100, "m").to("in").format("%.4<quantity>f")
|
181
|
-
#=> "3937.0079"
|
182
170
|
```
|
183
171
|
|
184
172
|
You can check more about formatting along with their examples
|
@@ -244,8 +232,6 @@ UnitMeasurements::Length.unit_for("m")
|
|
244
232
|
#=> #<UnitMeasurements::Unit: m (meter, meters, metre, metres)>
|
245
233
|
UnitMeasurements::Length.unit_for("z")
|
246
234
|
#=> nil
|
247
|
-
UnitMeasurements::Length.unit_for!("m")
|
248
|
-
#=> #<UnitMeasurements::Unit: m (meter, meters, metre, metres)>
|
249
235
|
UnitMeasurements::Length.unit_for!("z")
|
250
236
|
#=> Invalid unit: 'z'. (UnitMeasurements::UnitError)
|
251
237
|
```
|
@@ -329,10 +315,10 @@ The **`UnitMeasurements::Unit`** class is used to represent the units for a meas
|
|
329
315
|
|
330
316
|
### SI prefixed units
|
331
317
|
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
unit supports binary SI prefixes
|
318
|
+
Support for SI prefixed units is provided through the `si_unit` method. Units
|
319
|
+
declared this way automatically support all decimal SI prefixes. This method takes
|
320
|
+
an optional `add_binary_prefixes` parameter, which can be set to `true` if the
|
321
|
+
unit supports binary SI prefixes in addition to decimal SI prefixes.
|
336
322
|
|
337
323
|
#### Decimal SI prefixes
|
338
324
|
|
@@ -383,8 +369,7 @@ There are tons of units that are bundled in `unit_measurements`. You can check t
|
|
383
369
|
|
384
370
|
### Specifing units
|
385
371
|
|
386
|
-
By default, `unit_measurements`
|
387
|
-
when requiring the gem in the following manner.
|
372
|
+
By default, `unit_measurements` includes all unit groups automatically when you require the gem using:
|
388
373
|
|
389
374
|
```ruby
|
390
375
|
require "unit_measurements"
|
@@ -392,37 +377,22 @@ require "unit_measurements"
|
|
392
377
|
|
393
378
|
**You can skip these unit groups and only [build your own unit groups](#building-new-unit-groups) by doing:**
|
394
379
|
|
395
|
-
```ruby
|
396
|
-
require "unit_measurements/base"
|
397
|
-
```
|
398
|
-
|
399
|
-
or simply
|
400
|
-
|
401
380
|
```ruby
|
402
381
|
gem "unit_measurements", require: "unit_measurements/base"
|
403
382
|
```
|
404
383
|
|
405
384
|
**You can also use unit groups in your application as per your need as:**
|
406
385
|
|
407
|
-
```ruby
|
408
|
-
require "unit_measurements/base"
|
409
|
-
|
410
|
-
require "unit_measurements/unit_groups/length"
|
411
|
-
```
|
412
|
-
|
413
|
-
or
|
414
|
-
|
415
386
|
```ruby
|
416
387
|
gem "unit_measurements", require: ["unit_measurements/base", "unit_measurements/unit_groups/length"]
|
417
388
|
```
|
418
389
|
|
419
390
|
### Building new unit groups
|
420
391
|
|
421
|
-
This library provides simpler way to
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
and set primitive unit for each unit group using `primitive` method.
|
392
|
+
This library provides a simpler way to define your own unit groups. Use the
|
393
|
+
`UnitMeasurements.build` method to define units within it. You can also group
|
394
|
+
units by the unit system using the `system` method and set the primitive unit for
|
395
|
+
each unit group using the `primitive` method.
|
426
396
|
|
427
397
|
```ruby
|
428
398
|
UnitMeasurements::Time = UnitMeasurements.build do
|
@@ -441,7 +411,7 @@ UnitMeasurements::Time = UnitMeasurements.build do
|
|
441
411
|
unit "min", value: "60 s", aliases: ["hour", "hours"]
|
442
412
|
|
443
413
|
# You can also specify unit value as an array.
|
444
|
-
unit
|
414
|
+
unit "h", value: [60, "min"], aliases: ["day", "days"]
|
445
415
|
end
|
446
416
|
end
|
447
417
|
```
|
@@ -16,6 +16,11 @@ module UnitMeasurements
|
|
16
16
|
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
17
17
|
# @since 1.4.0
|
18
18
|
module Arithmetic
|
19
|
+
extend Forwardable
|
20
|
+
|
21
|
+
# Methods delegated from the Numeric.
|
22
|
+
def_delegators :@quantity, :zero?, :positive?, :negative?, :finite?, :infinite?
|
23
|
+
|
19
24
|
# Adds the quantity of the other measurement or a numeric value to the
|
20
25
|
# quantity of the current measurement.
|
21
26
|
#
|
@@ -78,6 +83,7 @@ module UnitMeasurements
|
|
78
83
|
def *(other)
|
79
84
|
arithmetic_operation(other, :*)
|
80
85
|
end
|
86
|
+
alias_method :scale, :*
|
81
87
|
|
82
88
|
# Divides the quantity of the current measurement by the quantity of the other
|
83
89
|
# measurement or a numeric value.
|
@@ -100,6 +106,70 @@ module UnitMeasurements
|
|
100
106
|
arithmetic_operation(other, :/)
|
101
107
|
end
|
102
108
|
|
109
|
+
# Raises the quantity of the current measurement to the power of the quantity of
|
110
|
+
# the other measurement or numeric value.
|
111
|
+
#
|
112
|
+
# When +other+ is an instance of +Measurement+, the quantity to raise
|
113
|
+
# is calculated by converting the +other+ measurement to the unit of the +current+
|
114
|
+
# measurement, and then the quantity of the +current+ measurement is raised to
|
115
|
+
# the converted quantity.
|
116
|
+
#
|
117
|
+
# @param [Numeric|Measurement] other
|
118
|
+
# The value to be raised. It can be a numeric value or another measurement.
|
119
|
+
#
|
120
|
+
# @example
|
121
|
+
# UnitMeasurements::Length.new(2, "km") ** UnitMeasurements::Length.new(3, "m")
|
122
|
+
# => 1.00208160507963279 km
|
123
|
+
#
|
124
|
+
# UnitMeasurements::Length.new(2, "km") ** 3
|
125
|
+
# => 8 km
|
126
|
+
#
|
127
|
+
# UnitMeasurements::Length.new(8, "km") ** 1/3r
|
128
|
+
# => 2 km
|
129
|
+
#
|
130
|
+
# @return [Measurement] A new +Measurement+ instance with the raised quantity.
|
131
|
+
#
|
132
|
+
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
133
|
+
# @since 5.1.0
|
134
|
+
def **(other)
|
135
|
+
arithmetic_operation(other, :**)
|
136
|
+
end
|
137
|
+
|
138
|
+
# Negates the quantity of the measurement.
|
139
|
+
#
|
140
|
+
# @example
|
141
|
+
# -UnitMeasurements::Length.new(2, "km")
|
142
|
+
# => -2 km
|
143
|
+
#
|
144
|
+
# -UnitMeasurements::Length.new(-2, "km")
|
145
|
+
# => 2 km
|
146
|
+
#
|
147
|
+
# @return [Measurement] A new +Measurement+ instance with the negated quantity.
|
148
|
+
#
|
149
|
+
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
150
|
+
# @since 5.1.0
|
151
|
+
def -@
|
152
|
+
self.class.new(-self.quantity, self.unit)
|
153
|
+
end
|
154
|
+
|
155
|
+
# Checks whether the quantity of the measurement is nonzero.
|
156
|
+
#
|
157
|
+
# @example
|
158
|
+
# UnitMeasurements::Length.new(2, "km").nonzero?
|
159
|
+
# => true
|
160
|
+
#
|
161
|
+
# UnitMeasurements::Length.new(0, "km").nonzero?
|
162
|
+
# => false
|
163
|
+
#
|
164
|
+
# @return [TrueClass|FalseClass]
|
165
|
+
# +true+ if the quantity is nonzero otherwise it returns +false+.
|
166
|
+
#
|
167
|
+
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
168
|
+
# @since 5.1.0
|
169
|
+
def nonzero?
|
170
|
+
quantity.nonzero? ? true : false
|
171
|
+
end
|
172
|
+
|
103
173
|
private
|
104
174
|
|
105
175
|
# @private
|
@@ -16,6 +16,8 @@ module UnitMeasurements
|
|
16
16
|
class ParseError < BaseError
|
17
17
|
# The input string that caused the error while parsing.
|
18
18
|
#
|
19
|
+
# @return [String] The input string that caused the error while parsing.
|
20
|
+
#
|
19
21
|
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
20
22
|
# @since 1.0.0
|
21
23
|
attr_reader :string
|
@@ -16,6 +16,8 @@ module UnitMeasurements
|
|
16
16
|
class UnitAlreadyDefinedError < BaseError
|
17
17
|
# The name of the unit that is already defined.
|
18
18
|
#
|
19
|
+
# @return [String] The name of the unit that is already defined.
|
20
|
+
#
|
19
21
|
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
20
22
|
# @since 1.0.0
|
21
23
|
attr_reader :unit
|
@@ -33,12 +33,25 @@ module UnitMeasurements
|
|
33
33
|
include Math
|
34
34
|
|
35
35
|
# Regular expression to match conversion strings.
|
36
|
+
#
|
37
|
+
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
38
|
+
# @since 1.0.0
|
36
39
|
CONVERSION_STRING_REGEXP = /(.+?)\s?(?:\s+(?:in|to|as)\s+(.+)|\z)/i.freeze
|
37
40
|
|
38
41
|
# Quantity of the measurement.
|
42
|
+
#
|
43
|
+
# @return [Numeric] Quantity of the measurement.
|
44
|
+
#
|
45
|
+
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
46
|
+
# @since 1.0.0
|
39
47
|
attr_reader :quantity
|
40
48
|
|
41
49
|
# The unit associated with the measurement.
|
50
|
+
#
|
51
|
+
# @return [Unit] The +unit+ instance associated with the measurement.
|
52
|
+
#
|
53
|
+
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
54
|
+
# @since 1.0.0
|
42
55
|
attr_reader :unit
|
43
56
|
|
44
57
|
# Initializes a new instance of +Measurement+ with a specified +quantity+
|
@@ -55,6 +68,12 @@ module UnitMeasurements
|
|
55
68
|
# UnitMeasurements::Length.new("2e+2", "km")
|
56
69
|
# => 200.0 km
|
57
70
|
#
|
71
|
+
# UnitMeasurements::Length.new("2e²", "km")
|
72
|
+
# => 200.0 km
|
73
|
+
#
|
74
|
+
# UnitMeasurements::Length.new("2e⁻²", "km")
|
75
|
+
# => 0.02 km
|
76
|
+
#
|
58
77
|
# @example Initializing the measurement with complex number and unit:
|
59
78
|
# UnitMeasurements::Length.new(Complex(2, 3), "km")
|
60
79
|
# => 2+3i km
|
@@ -75,6 +94,9 @@ module UnitMeasurements
|
|
75
94
|
# UnitMeasurements::Length.new("½", "km")
|
76
95
|
# => 0.5 km
|
77
96
|
#
|
97
|
+
# UnitMeasurements::Length.new("2 ½", "km")
|
98
|
+
# => 2.5 km
|
99
|
+
#
|
78
100
|
# @example Initializing the measurement with ratio and unit:
|
79
101
|
# UnitMeasurements::Length.new("1:2", "km")
|
80
102
|
# => 0.5 km
|
@@ -95,7 +117,8 @@ module UnitMeasurements
|
|
95
117
|
@unit = unit_from_unit_or_name!(unit)
|
96
118
|
end
|
97
119
|
|
98
|
-
# Converts the measurement to a +target_unit
|
120
|
+
# Converts the measurement to a +target_unit+ and returns new instance of the
|
121
|
+
# measurement.
|
99
122
|
#
|
100
123
|
# @example
|
101
124
|
# UnitMeasurements::Length.new(1, "m").convert_to("cm")
|
@@ -142,6 +165,7 @@ module UnitMeasurements
|
|
142
165
|
# @return [Measurement]
|
143
166
|
# The current +Measurement+ instance with updated +quantity+ and +unit+.
|
144
167
|
#
|
168
|
+
# @see #convert_to
|
145
169
|
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
146
170
|
# @since 1.0.0
|
147
171
|
def convert_to!(target_unit)
|
@@ -275,7 +299,8 @@ module UnitMeasurements
|
|
275
299
|
# @see Parser
|
276
300
|
# @see Normalizer
|
277
301
|
# @see CONVERSION_STRING_REGEXP
|
278
|
-
# @see _parse
|
302
|
+
# @see ._parse
|
303
|
+
# @see #convert_to
|
279
304
|
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
280
305
|
# @since 1.0.0
|
281
306
|
def parse(input)
|
@@ -309,6 +334,7 @@ module UnitMeasurements
|
|
309
334
|
#
|
310
335
|
# @return [Measurement] The +Measurement+ instance.
|
311
336
|
#
|
337
|
+
# @see Parser.parse
|
312
338
|
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
313
339
|
# @since 1.0.0
|
314
340
|
def _parse(string)
|
@@ -13,6 +13,8 @@ module UnitMeasurements
|
|
13
13
|
class Unit
|
14
14
|
# The name of the unit.
|
15
15
|
#
|
16
|
+
# @return [String] Name of the unit.
|
17
|
+
#
|
16
18
|
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
17
19
|
# @since 1.0.0
|
18
20
|
attr_reader :name
|
@@ -20,24 +22,33 @@ module UnitMeasurements
|
|
20
22
|
# The conversion value of the unit. It can be a numeric value or a string in
|
21
23
|
# the form of a number followed by a unit name (e.g., “10 m”).
|
22
24
|
#
|
25
|
+
# @return [String|Numeric|Array<Numeric, String>]
|
26
|
+
# Conversion value of the unit.
|
27
|
+
#
|
23
28
|
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
24
29
|
# @since 1.0.0
|
25
30
|
attr_reader :value
|
26
31
|
|
27
32
|
# A set of alternative names for the unit.
|
28
33
|
#
|
34
|
+
# @return [Set<String>] A set of alternative names.
|
35
|
+
#
|
29
36
|
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
30
37
|
# @since 1.0.0
|
31
38
|
attr_reader :aliases
|
32
39
|
|
33
40
|
# The system to which the unit belongs (e.g., “metric”, “imperial”).
|
34
41
|
#
|
42
|
+
# @return [String] Unit system in which the unit belongs.
|
43
|
+
#
|
35
44
|
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
36
45
|
# @since 4.0.0
|
37
46
|
attr_reader :system
|
38
47
|
|
39
48
|
# The unit group to which the unit belongs.
|
40
49
|
#
|
50
|
+
# @return [UnitGroup] Unit group in which the unit belongs.
|
51
|
+
#
|
41
52
|
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
42
53
|
# @since 1.0.0
|
43
54
|
attr_reader :unit_group
|
@@ -50,14 +61,13 @@ module UnitMeasurements
|
|
50
61
|
# @param [String|Symbol|NilClass] system The system to which the unit belongs.
|
51
62
|
# @param [UnitGroup|NilClass] unit_group The unit group to which the unit belongs.
|
52
63
|
#
|
53
|
-
# @see UnitGroup
|
54
64
|
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
55
65
|
# @since 1.0.0
|
56
66
|
def initialize(name, value:, aliases:, system:, unit_group: nil)
|
57
67
|
@name = name.to_s.freeze
|
58
68
|
@value = value
|
59
69
|
@aliases = Set.new(aliases.map(&:to_s).sort.map(&:freeze)).freeze
|
60
|
-
@system = system.to_s
|
70
|
+
@system = system.to_s.freeze
|
61
71
|
@unit_group = unit_group
|
62
72
|
end
|
63
73
|
|
@@ -71,7 +81,6 @@ module UnitMeasurements
|
|
71
81
|
#
|
72
82
|
# @return [Unit] A new unit with specified parameters.
|
73
83
|
#
|
74
|
-
# @see UnitGroup
|
75
84
|
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
76
85
|
# @since 1.0.0
|
77
86
|
def with(name: nil, value: nil, aliases: nil, system: nil, unit_group: nil)
|
@@ -30,6 +30,8 @@ module UnitMeasurements
|
|
30
30
|
# UnitMeasurements::Length.units
|
31
31
|
# => [#<UnitMeasurements::Unit: m (meter, meters, metre, metres)>, ...]
|
32
32
|
#
|
33
|
+
# @return [Array<Unit>] An array of +Unit+ instances.
|
34
|
+
#
|
33
35
|
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
34
36
|
# @since 1.0.0
|
35
37
|
attr_reader :units
|
@@ -171,7 +173,8 @@ module UnitMeasurements
|
|
171
173
|
#
|
172
174
|
# This method takes a unit system name as an argument and filters the units
|
173
175
|
# in the unit group to return only those units that belong to the specified
|
174
|
-
# unit system. It then returns an array containing these filtered units.
|
176
|
+
# unit system. It then returns an array containing these filtered units. If
|
177
|
+
# there are no units associated with unit system, it returns empty array.
|
175
178
|
#
|
176
179
|
# @example
|
177
180
|
# UnitMeasurements::Length.units_for("metric")
|
@@ -217,7 +220,7 @@ module UnitMeasurements
|
|
217
220
|
# @raise [BaseError]
|
218
221
|
# If there are no units associated with the provided +system_name+.
|
219
222
|
#
|
220
|
-
# @see units_for
|
223
|
+
# @see #units_for
|
221
224
|
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
222
225
|
# @since 5.0.0
|
223
226
|
def units_for!(system_name)
|
@@ -18,6 +18,8 @@ module UnitMeasurements
|
|
18
18
|
class UnitGroupBuilder
|
19
19
|
# An array to store the units defined using the builder.
|
20
20
|
#
|
21
|
+
# @return [Array<Unit>] An array of +Unit+ instances.
|
22
|
+
#
|
21
23
|
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
22
24
|
# @since 1.0.0
|
23
25
|
attr_reader :units
|
@@ -70,7 +72,7 @@ module UnitMeasurements
|
|
70
72
|
@units += build_si_units(name, value: value, add_binary_prefixes: add_binary_prefixes, aliases: aliases)
|
71
73
|
end
|
72
74
|
|
73
|
-
# Constructs and returns a +UnitGroup+
|
75
|
+
# Constructs and returns a +UnitGroup+ instance based on the units defined
|
74
76
|
# using the builder.
|
75
77
|
#
|
76
78
|
# @return [UnitGroup]
|
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.1.1
|
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-10-
|
11
|
+
date: 2023-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- ".github/workflows/pages.yml"
|
98
98
|
- ".gitignore"
|
99
99
|
- ".rspec"
|
100
|
+
- ".yardopts"
|
100
101
|
- CHANGELOG.md
|
101
102
|
- Gemfile
|
102
103
|
- Gemfile.lock
|