unit_measurements 1.2.0 → 1.3.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 +9 -1
- data/Gemfile.lock +1 -1
- data/README.md +19 -0
- data/lib/unit_measurements/base.rb +1 -0
- data/lib/unit_measurements/comparison.rb +22 -0
- data/lib/unit_measurements/measurement.rb +2 -0
- 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: 3562e30ce7bfed682e67fbdc5c9d8d30b011a6cd16996b7efe6860622abf25d5
|
4
|
+
data.tar.gz: af4224714284377ebd6aea3a78c4842078f708eeaf06500658ef45f151192373
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22a6a8f0b97a5ef1845448bcf219fbd2d0228b3d74b409e93ce596f7648d67207ea5caa64f39e0c0dd9083bf6425c1012bbf11f25624faf718f377307b698309
|
7
|
+
data.tar.gz: 1a436d77f1a99a7eb838e397b0038b7aba73fe19d3acf7aa0e02dbd3d482beeb2fd6b33b648d2b02514681ba6b792076596f761dbca41fb0eab3985d84209f27
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,16 @@
|
|
1
|
+
## [1.3.0](https://github.com/shivam091/unit_measurements/compare/v1.2.0...v1.3.0) - 2023-08-16
|
2
|
+
|
3
|
+
### What's new
|
4
|
+
|
5
|
+
- Added ability to compare two measurements of the same unit group.
|
6
|
+
|
7
|
+
----------
|
8
|
+
|
1
9
|
## [1.2.0](https://github.com/shivam091/unit_measurements/compare/v1.1.0...v1.2.0) - 2023-08-15
|
2
10
|
|
3
11
|
### What's new
|
4
12
|
|
5
|
-
- Added support to specify unit value as an `array` of number and unit.
|
13
|
+
- Added support to specify unit value as an `array` of number and unit.
|
6
14
|
|
7
15
|
----------
|
8
16
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -303,6 +303,25 @@ UnitMeasurements::Weight.unit_or_alias?(:gramme)
|
|
303
303
|
#=> true
|
304
304
|
```
|
305
305
|
|
306
|
+
### Comparisons
|
307
|
+
|
308
|
+
You have ability to compare the measurements with the same or different units within the same unit group.
|
309
|
+
For example, comparing weight with weight will work, comparing a weight with a area would fail.
|
310
|
+
Allowed comparisons are `==`, `!=`, `>`, `>=`, `<`, and `<=`.
|
311
|
+
|
312
|
+
```ruby
|
313
|
+
UnitMeasurements::Weight.new(1, "kg") == UnitMeasurements::Weight.new(1, :kg)
|
314
|
+
#=> true
|
315
|
+
UnitMeasurements::Weight.parse("1 kg") == UnitMeasurements::Weight.parse("1000 g")
|
316
|
+
#=> true
|
317
|
+
UnitMeasurements::Weight.parse("1 kg") != UnitMeasurements::Weight.parse("1 g")
|
318
|
+
#=> true
|
319
|
+
UnitMeasurements::Weight.parse("1 kg") <= UnitMeasurements::Weight.parse("0.5 kg")
|
320
|
+
#=> false
|
321
|
+
UnitMeasurements::Weight.parse("1 kg") >= UnitMeasurements::Weight.parse("0.5 kg")
|
322
|
+
#=> true
|
323
|
+
```
|
324
|
+
|
306
325
|
## Units
|
307
326
|
|
308
327
|
The **`UnitMeasurements::Unit`** class is used to represent the units for a measurement.
|
@@ -28,6 +28,7 @@ require "unit_measurements/unit_group"
|
|
28
28
|
require "unit_measurements/normalizer"
|
29
29
|
require "unit_measurements/parser"
|
30
30
|
require "unit_measurements/formatter"
|
31
|
+
require "unit_measurements/comparison"
|
31
32
|
require "unit_measurements/measurement"
|
32
33
|
|
33
34
|
require "unit_measurements/errors/unit_error"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module UnitMeasurements
|
6
|
+
module Comparison
|
7
|
+
include Comparable
|
8
|
+
|
9
|
+
# Compares the quantities of two measurements within the same unit group.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# UnitMeasurements::Weight.new(1, "kg") == UnitMeasurements::Weight.new(1, :kg)
|
13
|
+
# => true
|
14
|
+
#
|
15
|
+
# @return [Boolean]
|
16
|
+
def <=>(object)
|
17
|
+
return nil unless object.is_a?(self.class)
|
18
|
+
|
19
|
+
quantity <=> object.convert_to(unit.name).quantity
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
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: 1.
|
4
|
+
version: 1.3.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-09-
|
11
|
+
date: 2023-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- Rakefile
|
105
105
|
- lib/unit_measurements.rb
|
106
106
|
- lib/unit_measurements/base.rb
|
107
|
+
- lib/unit_measurements/comparison.rb
|
107
108
|
- lib/unit_measurements/errors/parse_error.rb
|
108
109
|
- lib/unit_measurements/errors/unit_already_defined_error.rb
|
109
110
|
- lib/unit_measurements/errors/unit_error.rb
|