unitwise 2.0.0 → 2.2.0
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/.ruby-version +1 -1
- data/.travis.yml +5 -10
- data/CHANGELOG.md +38 -0
- data/Gemfile +1 -5
- data/README.md +33 -4
- data/data/base_unit.yaml +2 -2
- data/data/derived_unit.yaml +359 -321
- data/data/prefix.yaml +25 -25
- data/lib/unitwise/atom.rb +33 -4
- data/lib/unitwise/errors.rb +5 -2
- data/lib/unitwise/expression/decomposer.rb +21 -9
- data/lib/unitwise/expression/matcher.rb +3 -8
- data/lib/unitwise/expression/parser.rb +11 -4
- data/lib/unitwise/functional.rb +8 -0
- data/lib/unitwise/measurement.rb +1 -5
- data/lib/unitwise/number.rb +62 -0
- data/lib/unitwise/prefix.rb +0 -6
- data/lib/unitwise/scale.rb +2 -16
- data/lib/unitwise/standard/function.rb +2 -2
- data/lib/unitwise/standard/prefix.rb +4 -3
- data/lib/unitwise/standard/scale.rb +2 -2
- data/lib/unitwise/term.rb +2 -2
- data/lib/unitwise/unit.rb +3 -3
- data/lib/unitwise/version.rb +1 -1
- data/lib/unitwise.rb +14 -1
- data/test/support/scale_tests.rb +16 -22
- data/test/test_helper.rb +1 -2
- data/test/unitwise/atom_test.rb +38 -2
- data/test/unitwise/expression/matcher_test.rb +3 -3
- data/test/unitwise/functional_test.rb +1 -1
- data/test/unitwise/measurement_test.rb +8 -1
- data/test/unitwise/number_test.rb +52 -0
- data/test/unitwise_test.rb +21 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85c8f9524b9cffa66bf645e212104c3985e4efa3
|
4
|
+
data.tar.gz: b8a7623a2eb3186faef2d8c11056307f454d29ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cb7314cfefef4d4f4172c8608463b4e2f31c70aecc54115b4584eff913f76301a5114be12b79c64926b5ca19d33f106916c798643eb4999f7b16bce4e911fdb
|
7
|
+
data.tar.gz: c7e97adc9d4dc60f53f6ccff5d1d8b3522361b7f0118f08ccb61a8cc58cacb005e34802f6f1219c9b4ff3546bbc7749c171e47a514a362e4dfa9fe9d4d52699d
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.4.1
|
data/.travis.yml
CHANGED
@@ -3,18 +3,13 @@ cache: bundler
|
|
3
3
|
bundler_args: --without yard pry
|
4
4
|
sudo: false
|
5
5
|
rvm:
|
6
|
-
-
|
7
|
-
- 2.
|
8
|
-
- 2.1
|
9
|
-
-
|
6
|
+
- 2.2.7
|
7
|
+
- 2.3.4
|
8
|
+
- 2.4.1
|
9
|
+
- jruby-9.1.8.0
|
10
10
|
- ruby-head
|
11
|
-
-
|
11
|
+
- jruby-head
|
12
12
|
matrix:
|
13
|
-
include:
|
14
|
-
- rvm: jruby-19mode
|
15
|
-
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
16
|
-
- rvm: jruby-head
|
17
|
-
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
18
13
|
allow_failures:
|
19
14
|
- rvm: ruby-head
|
20
15
|
- rvm: jruby-head
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,44 @@ version 1.0.0.
|
|
5
5
|
|
6
6
|
Unitwise uses semantic versioning.
|
7
7
|
|
8
|
+
## Unreleased
|
9
|
+
|
10
|
+
## 2.2.0 - 2017-07-14
|
11
|
+
|
12
|
+
### Fixed
|
13
|
+
|
14
|
+
- Default units now stored as BigDecimal or Integer to reduce floating point
|
15
|
+
accuracy loss.
|
16
|
+
- Added missing conversion for Degree Réaumur.
|
17
|
+
|
18
|
+
### Changed
|
19
|
+
|
20
|
+
- Performing mathematical operations or converting units will now use Rational
|
21
|
+
math to prevent accuracy loss. In most cases, this means converted/operated
|
22
|
+
on `Measurement`s will have a `Rational` `#value`. If you have an explicit
|
23
|
+
dependency on the exact `Numeric` type that `Measurement#value` returns,
|
24
|
+
consider using `#to_f` or `#to_i` instead.
|
25
|
+
|
26
|
+
### Removed
|
27
|
+
|
28
|
+
- Support for MRI 2.1
|
29
|
+
|
30
|
+
## 2.1.0 - 2017-04-28
|
31
|
+
|
32
|
+
### Removed
|
33
|
+
|
34
|
+
- Support for Ruby MRI 1.9.3, MRI 2.0, and Rubinius
|
35
|
+
|
36
|
+
### Added
|
37
|
+
|
38
|
+
- `Unitwise.register` is a new method that allows user defined units
|
39
|
+
- Support for MRI 2.3 and 2.4
|
40
|
+
|
41
|
+
### Changed
|
42
|
+
|
43
|
+
- Unit data refreshed from latest UCUM spec. Most notably, some metric atoms
|
44
|
+
names have seen case changes.
|
45
|
+
|
8
46
|
## 2.0.0 - 2015-09-13
|
9
47
|
|
10
48
|
### Fixed
|
data/Gemfile
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
gem 'coveralls', '~> 0.7'
|
4
|
-
|
5
|
-
gem 'bigdecimal', '~> 1.2.6', :platform => :mri
|
6
|
-
else
|
7
|
-
gem 'bigdecimal', '~> 1.2.5', :platform => :mri
|
8
|
-
end
|
4
|
+
gem 'bigdecimal', '>= 1.2.6', :platform => :mri
|
9
5
|
|
10
6
|
gemspec
|
data/README.md
CHANGED
@@ -237,17 +237,46 @@ Unitwise(1, "meter/s") # Does not work, mixed designations (name and primar
|
|
237
237
|
Unitwise(1, "meter") / Unitwise(1, "s") # Also works
|
238
238
|
```
|
239
239
|
|
240
|
+
|
241
|
+
### Adding custom units
|
242
|
+
|
243
|
+
While UCUM's list of units is rather exhaustive, there may still be occasions
|
244
|
+
where you need custom or uncommon measurements. You can add them yourself
|
245
|
+
with `Unitwise.register`, which will allow you to convert to or from the new
|
246
|
+
unit.
|
247
|
+
|
248
|
+
For example, if your app needed to pour "3 fingers" of bourbon, you could
|
249
|
+
register an atom for that:
|
250
|
+
|
251
|
+
```ruby
|
252
|
+
Unitwise.register(
|
253
|
+
names: ["finger", "fingers"],
|
254
|
+
symbol: "🥃",
|
255
|
+
primary_code: "fng",
|
256
|
+
secondary_code: "fng",
|
257
|
+
scale: {
|
258
|
+
value: 1.0,
|
259
|
+
unit_code: '[foz_us]'
|
260
|
+
},
|
261
|
+
property: 'fluid volume'
|
262
|
+
)
|
263
|
+
|
264
|
+
Unitwise(1, "gallon").to_fingers
|
265
|
+
# => #<Unitwise::Measurement value=0.153721590464621430998E3 unit=fingers>
|
266
|
+
|
267
|
+
Unitwise(1, "🥃").to_cup
|
268
|
+
# => #<Unitwise::Measurement value=0.125 unit=cup>
|
269
|
+
```
|
270
|
+
|
240
271
|
## Supported Ruby Versions
|
241
272
|
|
242
273
|
This library aims to support and is tested against the following Ruby
|
243
274
|
implementations:
|
244
275
|
|
245
|
-
* Ruby 1.9.3
|
246
|
-
* Ruby 2.0.0
|
247
|
-
* Ruby 2.1
|
248
276
|
* Ruby 2.2
|
277
|
+
* Ruby 2.3
|
278
|
+
* Ruby 2.4
|
249
279
|
* [JRuby](http://jruby.org/)
|
250
|
-
* [Rubinius](http://rubini.us/)
|
251
280
|
|
252
281
|
If something doesn't work on one of these versions, it's a bug.
|
253
282
|
|
data/data/base_unit.yaml
CHANGED
@@ -23,13 +23,13 @@
|
|
23
23
|
:secondary_code: RAD
|
24
24
|
:property: plane angle
|
25
25
|
:dim: A
|
26
|
-
- :names:
|
26
|
+
- :names: kelvin
|
27
27
|
:symbol: K
|
28
28
|
:primary_code: K
|
29
29
|
:secondary_code: K
|
30
30
|
:property: temperature
|
31
31
|
:dim: C
|
32
|
-
- :names:
|
32
|
+
- :names: coulomb
|
33
33
|
:symbol: C
|
34
34
|
:primary_code: C
|
35
35
|
:secondary_code: C
|