measured 2.5.1 → 2.5.2
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/.travis.yml +5 -9
- data/CHANGELOG.md +6 -0
- data/lib/measured/unit.rb +5 -5
- data/lib/measured/unit_system.rb +7 -1
- data/lib/measured/version.rb +1 -1
- data/measured.gemspec +1 -1
- data/test/test_helper.rb +1 -1
- data/test/unit_system_builder_test.rb +10 -0
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce0f6c7c10571db0dd0d844638dd0bae637d2f9b13e87c29700bf9db51d84197
|
4
|
+
data.tar.gz: 936e5b74c36c65ca8393b94684b13341ff84d6981cfa34379af9cd0f8bdbed94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95eea761fff7e89716925729c8dae771b6274705390622930cf58443bc1d18bd2405bc65b13fa46b1c232ad249a231b0c1d5d7bedafa5d8262f860d94ac24437
|
7
|
+
data.tar.gz: b9d5ed9a9dc1a0fe8710a62c6c7d673d53c4fee4161f76452ab1f1b708edcb1a8ca081577dd4fb012358b375952d675f8e0bfc8d253f5b8519a024c944806bf1
|
data/.travis.yml
CHANGED
@@ -2,20 +2,16 @@ language: ruby
|
|
2
2
|
sudo: false
|
3
3
|
cache: bundler
|
4
4
|
rvm:
|
5
|
-
- 2.
|
6
|
-
- 2.
|
7
|
-
- 2.
|
8
|
-
- 2.
|
5
|
+
- 2.4.9
|
6
|
+
- 2.5.7
|
7
|
+
- 2.6.5
|
8
|
+
- 2.7.0
|
9
9
|
gemfile:
|
10
10
|
- Gemfile
|
11
11
|
- gemfiles/activesupport-5.0.gemfile
|
12
12
|
- gemfiles/activesupport-5.1.gemfile
|
13
13
|
- gemfiles/activesupport-6.0.gemfile
|
14
|
-
before_script:
|
15
|
-
- gem update --system
|
16
14
|
matrix:
|
17
15
|
exclude:
|
18
16
|
- gemfile: gemfiles/activesupport-6.0.gemfile
|
19
|
-
rvm: 2.
|
20
|
-
- gemfile: gemfiles/activesupport-6.0.gemfile
|
21
|
-
rvm: 2.4.5
|
17
|
+
rvm: 2.4.9
|
data/CHANGELOG.md
CHANGED
data/lib/measured/unit.rb
CHANGED
@@ -14,12 +14,12 @@ class Measured::Unit
|
|
14
14
|
@unit_system = unit_system
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def with(name: nil, unit_system: nil, aliases: nil, value: nil)
|
18
18
|
self.class.new(
|
19
|
-
name,
|
20
|
-
aliases: aliases,
|
21
|
-
value: @conversion_string,
|
22
|
-
unit_system: unit_system
|
19
|
+
name || self.name,
|
20
|
+
aliases: aliases || self.aliases,
|
21
|
+
value: value || @conversion_string,
|
22
|
+
unit_system: unit_system || self.unit_system
|
23
23
|
)
|
24
24
|
end
|
25
25
|
|
data/lib/measured/unit_system.rb
CHANGED
@@ -3,7 +3,13 @@ class Measured::UnitSystem
|
|
3
3
|
attr_reader :units, :unit_names, :unit_names_with_aliases
|
4
4
|
|
5
5
|
def initialize(units, cache: nil)
|
6
|
-
@units = units.map { |unit| unit.
|
6
|
+
@units = units.map { |unit| unit.with(unit_system: self) }
|
7
|
+
@units = @units.map do |unit|
|
8
|
+
next unit unless unit.conversion_unit
|
9
|
+
conversion_unit = @units.find { |u| u.names.include?(unit.conversion_unit) }
|
10
|
+
next unit unless conversion_unit
|
11
|
+
unit.with(value: [unit.conversion_amount, conversion_unit.name])
|
12
|
+
end
|
7
13
|
@unit_names = @units.map(&:name).sort.freeze
|
8
14
|
@unit_names_with_aliases = @units.flat_map(&:names).sort.freeze
|
9
15
|
@unit_name_to_unit = @units.each_with_object({}) do |unit, hash|
|
data/lib/measured/version.rb
CHANGED
data/measured.gemspec
CHANGED
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "rake", "> 10.0"
|
24
24
|
spec.add_development_dependency "minitest", "> 5.5.1"
|
25
25
|
spec.add_development_dependency "minitest-reporters"
|
26
|
-
spec.add_development_dependency "mocha", "
|
26
|
+
spec.add_development_dependency "mocha", ">= 1.4.0"
|
27
27
|
spec.add_development_dependency "pry"
|
28
28
|
end
|
data/test/test_helper.rb
CHANGED
@@ -39,6 +39,16 @@ class Measured::UnitSystemBuilderTest < ActiveSupport::TestCase
|
|
39
39
|
assert_equal 'BOLD', measurable.unit_system.unit_for!(:BOLD).name
|
40
40
|
end
|
41
41
|
|
42
|
+
test "#unit traverses aliases" do
|
43
|
+
measurable = Measured.build do
|
44
|
+
unit :piece, aliases: [:pieces]
|
45
|
+
unit :dozen, aliases: [:dz], value: "12 pieces"
|
46
|
+
end
|
47
|
+
|
48
|
+
assert_equal 12, measurable.unit_system.units.last.conversion_amount
|
49
|
+
assert_equal "piece", measurable.unit_system.units.last.conversion_unit
|
50
|
+
end
|
51
|
+
|
42
52
|
test "#si_unit adds 21 new units" do
|
43
53
|
measurable = Measured.build do
|
44
54
|
unit :ft
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: measured
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.5.
|
4
|
+
version: 2.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin McPhillips
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-01-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -72,16 +72,16 @@ dependencies:
|
|
72
72
|
name: mocha
|
73
73
|
requirement: !ruby/object:Gem::Requirement
|
74
74
|
requirements:
|
75
|
-
- - "
|
75
|
+
- - ">="
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: 1.
|
77
|
+
version: 1.4.0
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
80
|
version_requirements: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
|
-
- - "
|
82
|
+
- - ">="
|
83
83
|
- !ruby/object:Gem::Version
|
84
|
-
version: 1.
|
84
|
+
version: 1.4.0
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
86
|
name: pry
|
87
87
|
requirement: !ruby/object:Gem::Requirement
|
@@ -175,8 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
175
|
- !ruby/object:Gem::Version
|
176
176
|
version: '0'
|
177
177
|
requirements: []
|
178
|
-
|
179
|
-
rubygems_version: 2.7.6
|
178
|
+
rubygems_version: 3.0.3
|
180
179
|
signing_key:
|
181
180
|
specification_version: 4
|
182
181
|
summary: Encapsulate measurements with their units in Ruby
|