unit_measurements 5.0.0 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a7a4305ab13c8d9d8d52eaf7c9e4646757dc8eee71af5ec8314f6a2b702f929
4
- data.tar.gz: 9cb9fc75b29f7745278ca27ce32fce621a29427e6e08202590eec52ff90c4e66
3
+ metadata.gz: a8e055ec9a81c6c27050136128e36d6bceba2b3292e6494a2bbd3305ccbcb20b
4
+ data.tar.gz: 381e87126aaa72bd762f537fe6be8638adbf07105ed992009a8298f6d6159de4
5
5
  SHA512:
6
- metadata.gz: 46ddf50754159eb8dcaf4f753378fe19f912ac0d8316ecdd959b23620ed7ca2ef1a1122ce0a35d0a33bd0d643fbe7e6572a83348ca2faf3ab6815ce64c61e9d4
7
- data.tar.gz: 9b84900e75d14377ebe58e8a21d75aaca6ae1329ce2be56768a7f24f4476782e27d8312fa65045c7398d6c67eb78ff2b01ea5b6da2263e53899eb21f015cb246
6
+ metadata.gz: b8b3831f2e780623cd1d7d8e86d7f4687c58ed380dabccfa2eff81ab1c9cb13c8295970c1980acbf920ee00bffcba6fd3d310563fc3d27ecbc6946e14fadddea
7
+ data.tar.gz: d45c0207c736ca65b6041483d609a6390784fd60334c49220d36580f5fb3e3882c1f5a49d5951e6bc3f46386769cd18168bb8fcb6e897fb9b742fa3445acd8b7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## [5.1.0](https://github.com/shivam091/unit_measurements/compare/v5.0.0...v5.1.0) - 2023-10-19
2
+
3
+ ### What's new
4
+
5
+ - Added new methods (`**`, `-@`, `nonzero?`, `zero?`, `positive?`, `negative?`,
6
+ `finite?`, and `infinite?`) to perform arithmetic operations.
7
+ - Added new alias `scale` for `**` arithmetic method.
8
+
9
+ ### What's updated
10
+
11
+ - Updated readme and documentation.
12
+ - Updated documentation hosting link to `https://rubydoc.info/gems/unit_measurements`.
13
+
14
+ ----------
15
+
1
16
  ## [5.0.0](https://github.com/shivam091/unit_measurements/compare/v4.12.0...v5.0.0) - 2023-10-18
2
17
 
3
18
  ### What's new
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unit_measurements (5.0.0)
4
+ unit_measurements (5.1.0)
5
5
  activesupport (~> 7.0)
6
6
 
7
7
  GEM
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
- ## Advantages
25
+ ## Features
26
26
 
27
- 1. It provides easy conversion between units.
28
- 2. It is lightweight and easily extensible to include other units and conversions.
29
- 3. It has built in support for various [unit groups](https://github.com/shivam091/unit_measurements/blob/main/units.md).
30
- 4. It has well organized and very descriptive documentation published [here](https://shivam091.github.io/unit_measurements).
31
- 5. It can convert `complex`, `fractional`, `mixed fractional`, `scientific` numbers, and `ratios`.
27
+ - Easy unit conversion.
28
+ - Lightweight and extensible for adding custom units and conversions.
29
+ - Supports various [unit groups](https://github.com/shivam091/unit_measurements/blob/main/units.md).
30
+ - Well-documented: [Documentation](https://rubydoc.info/gems/unit_measurements).
31
+ - Parses complex, fractional, mixed fractional, scientific numbers, and ratios.
32
32
 
33
33
  ## Disclaimer
34
34
 
35
- _The unit conversions presented in `unit_measurements` are provided for reference and general informational purposes.
36
- While we aim to offer accurate conversions, we cannot guarantee their precision in all scenarios.
37
- Users are advised to cross-verify conversions as needed for their specific use cases._
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
 
@@ -127,7 +127,7 @@ UnitMeasurements::Length.parse("2e+2 km to m")
127
127
  #=> 200000.0 m
128
128
  ```
129
129
  You can check supported special characters for exponents
130
- [here](https://shivam091.github.io/unit_measurements/UnitMeasurements/Normalizer.html).
130
+ [here](https://rubydoc.info/gems/unit_measurements/UnitMeasurements/Normalizer.html).
131
131
 
132
132
  **Parse complex numbers, source unit, and (or) target unit:**
133
133
 
@@ -143,24 +143,16 @@ 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
157
- [here](https://shivam091.github.io/unit_measurements/UnitMeasurements/Normalizer.html).
151
+ [here](https://rubydoc.info/gems/unit_measurements/UnitMeasurements/Normalizer.html).
158
152
 
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,16 +165,12 @@ 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
185
- [here](https://shivam091.github.io/unit_measurements/UnitMeasurements/Formatter.html).
173
+ [here](https://rubydoc.info/gems/unit_measurements/UnitMeasurements/Formatter.html).
186
174
 
187
175
  **Extract the unit and the quantity from measurement:**
188
176
 
@@ -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
  ```
@@ -279,7 +265,7 @@ UnitMeasurements::Length.parse("1 km") != UnitMeasurements::Length.parse("1 m")
279
265
  ```
280
266
 
281
267
  You can check supported comparisons along with their examples
282
- [here](https://shivam091.github.io/unit_measurements/UnitMeasurements/Comparison.html).
268
+ [here](https://rubydoc.info/gems/unit_measurements/UnitMeasurements/Comparison.html).
283
269
 
284
270
  ### Arithmetic
285
271
 
@@ -296,7 +282,7 @@ UnitMeasurements::Length.new(2, "km") * 2+2i
296
282
  ```
297
283
 
298
284
  You can check supported arithmetic operations along with their examples
299
- [here](https://shivam091.github.io/unit_measurements/UnitMeasurements/Arithmetic.html).
285
+ [here](https://rubydoc.info/gems/unit_measurements/UnitMeasurements/Arithmetic.html).
300
286
 
301
287
  ### Math
302
288
 
@@ -308,7 +294,7 @@ UnitMeasurements::Length.new(17.625, "m").round
308
294
  ```
309
295
 
310
296
  You can check supported mathematical functions along with their examples
311
- [here](https://shivam091.github.io/unit_measurements/UnitMeasurements/Math.html).
297
+ [here](https://rubydoc.info/gems/unit_measurements/UnitMeasurements/Math.html).
312
298
 
313
299
  ### Conversions
314
300
 
@@ -321,7 +307,7 @@ UnitMeasurements::Length.new(2.25567, "km").to_i
321
307
  ```
322
308
 
323
309
  You can check more about them along with their examples
324
- [here](https://shivam091.github.io/unit_measurements/UnitMeasurements/Conversion.html).
310
+ [here](https://rubydoc.info/gems/unit_measurements/UnitMeasurements/Conversion.html).
325
311
 
326
312
  ## Units
327
313
 
@@ -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
- There is support for SI prefixed units through the use of `si_unit` method.
333
- Units declared through it will have automatic support for all decimal SI prefixes.
334
- This method takes `add_binary_prefixes` parameter which can be set to true, if the
335
- unit supports binary SI prefixes along with decimal 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` ships with all the unit groups and this happens automatically
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 build your own unit groups. To build new unit group,
422
- use `UnitMeasurements.build` method in order to define units within it:
423
-
424
- For convenience, you also have ability to group units by the unit system using `system` method
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 :h, value: [60, "min"], aliases: ["day", "days"]
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
@@ -15,6 +15,8 @@ module UnitMeasurements
15
15
  class UnitError < BaseError
16
16
  # The name of the invalid unit.
17
17
  #
18
+ # @return [String] The name of the invalid unit.
19
+ #
18
20
  # @author {Harshal V. Ladhe}[https://shivam091.github.io/]
19
21
  # @since 1.0.0
20
22
  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+ object based on the units defined
75
+ # Constructs and returns a +UnitGroup+ instance based on the units defined
74
76
  # using the builder.
75
77
  #
76
78
  # @return [UnitGroup]
@@ -4,5 +4,5 @@
4
4
 
5
5
  module UnitMeasurements
6
6
  # Current stable version.
7
- VERSION = "5.0.0"
7
+ VERSION = "5.1.0"
8
8
  end
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
23
23
 
24
24
  spec.metadata["homepage_uri"] = spec.homepage
25
- spec.metadata["documentation_uri"] = "https://shivam091.github.io/unit_measurements"
25
+ spec.metadata["documentation_uri"] = "https://rubydoc.info/gems/unit_measurements"
26
26
  spec.metadata["source_code_uri"] = "https://github.com/shivam091/unit_measurements"
27
27
  spec.metadata["changelog_uri"] = "https://github.com/shivam091/unit_measurements/blob/main/CHANGELOG.md"
28
28
  spec.metadata["bug_tracker_uri"] = "https://github.com/shivam091/unit_measurements/issues"
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.0.0
4
+ version: 5.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-10-18 00:00:00.000000000 Z
11
+ date: 2023-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -178,7 +178,7 @@ licenses:
178
178
  metadata:
179
179
  allowed_push_host: https://rubygems.org
180
180
  homepage_uri: https://github.com/shivam091/unit_measurements
181
- documentation_uri: https://shivam091.github.io/unit_measurements
181
+ documentation_uri: https://rubydoc.info/gems/unit_measurements
182
182
  source_code_uri: https://github.com/shivam091/unit_measurements
183
183
  changelog_uri: https://github.com/shivam091/unit_measurements/blob/main/CHANGELOG.md
184
184
  bug_tracker_uri: https://github.com/shivam091/unit_measurements/issues