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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d1b9cef9a108d5a0930ca0fd0a2e156a5653893786eb97159c7c4c801e71970
4
- data.tar.gz: a4ef6d728ad141f2d19ab5151ea3205ce2098710b8facf1d979b4299e8a72530
3
+ metadata.gz: aac3030ed1c46bb4bdfe831bc9bedb29ad2a8b0e28595ba4726b2a3ff5e24791
4
+ data.tar.gz: 9179c7b41ef7e84b6864ef98ccb45210ab34b2488830aa3de5552659b7f39039
5
5
  SHA512:
6
- metadata.gz: 360ba9c4e48722b51fc9d9dd049ddd2217aac3c30d3de6afb66ee10d31d466d15e743f6437ceb6d7f232844378f6ca3be995447627e4264c1c25d1e7db9690e5
7
- data.tar.gz: 8bed02dfd85b3933e128e2c390a12f5f63f15950ddadd053063822f00be4b8c3464992ad0d51440bebcbad78c7b0df1b80cdcb341b1d1dbeea0d1171ed06ffdc
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
- ## What's fixed
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unit_measurements (1.5.0)
4
+ unit_measurements (1.5.1)
5
5
  activesupport (~> 7.0)
6
6
 
7
7
  GEM
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
@@ -68,6 +68,7 @@ module UnitMeasurements
68
68
 
69
69
  def arithmetic_operation(other, operator)
70
70
  other, _ = coerce(other)
71
+
71
72
  self.class.new(self.quantity.public_send(operator, other.convert_to(self.unit).quantity), self.unit)
72
73
  end
73
74
  end
@@ -8,6 +8,7 @@ module UnitMeasurements
8
8
 
9
9
  def initialize(string)
10
10
  @string = string
11
+
11
12
  super("Unable to parse: '#{string}'.")
12
13
  end
13
14
  end
@@ -8,6 +8,7 @@ module UnitMeasurements
8
8
 
9
9
  def initialize(unit)
10
10
  @unit = unit
11
+
11
12
  super("Unit already defined: '#{unit}'.")
12
13
  end
13
14
  end
@@ -8,6 +8,7 @@ module UnitMeasurements
8
8
 
9
9
  def initialize(unit)
10
10
  @unit = unit
11
+
11
12
  super("Invalid unit: '#{unit}'.")
12
13
  end
13
14
  end
@@ -22,6 +22,7 @@ module UnitMeasurements
22
22
  # @return [String]
23
23
  def format(format = nil)
24
24
  kwargs = {quantity: quantity, unit: unit.to_s}
25
+
25
26
  (format || DEFAULT_FORMAT) % kwargs
26
27
  end
27
28
  end
@@ -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
@@ -3,5 +3,5 @@
3
3
  # -*- warn_indent: true -*-
4
4
 
5
5
  module UnitMeasurements
6
- VERSION = "1.5.0"
6
+ VERSION = "1.5.1"
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unit_measurements
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harshal LADHE