measured 2.5.1 → 2.5.2

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: ded401e32179325e80114d1a2c184a1c03599156b7e332291f6e3a114bc1c7fb
4
- data.tar.gz: 680d3cf30b58647232717d4f82b5eb0120e4e95f04f8b771cf70540ee860de0e
3
+ metadata.gz: ce0f6c7c10571db0dd0d844638dd0bae637d2f9b13e87c29700bf9db51d84197
4
+ data.tar.gz: 936e5b74c36c65ca8393b94684b13341ff84d6981cfa34379af9cd0f8bdbed94
5
5
  SHA512:
6
- metadata.gz: 5827bf20fcbb6aa5380e1cb68a876629235b1abbda98b74b5d562a483f812a6b7f9579f2b581803a1f5efacccb479bd651aae08bbb863ab40201c5af73f6b995
7
- data.tar.gz: af772cae9ae42e41c6f1b99a2757713a18236107ac79f97d26ca3709e1618c6956ad993900897e59ff30fd7904ec53ee35d7d98cdcd8aa1df126415b617e16f2
6
+ metadata.gz: 95eea761fff7e89716925729c8dae771b6274705390622930cf58443bc1d18bd2405bc65b13fa46b1c232ad249a231b0c1d5d7bedafa5d8262f860d94ac24437
7
+ data.tar.gz: b9d5ed9a9dc1a0fe8710a62c6c7d673d53c4fee4161f76452ab1f1b708edcb1a8ca081577dd4fb012358b375952d675f8e0bfc8d253f5b8519a024c944806bf1
@@ -2,20 +2,16 @@ language: ruby
2
2
  sudo: false
3
3
  cache: bundler
4
4
  rvm:
5
- - 2.3.8
6
- - 2.4.5
7
- - 2.5.5
8
- - 2.6.3
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.3.8
20
- - gemfile: gemfiles/activesupport-6.0.gemfile
21
- rvm: 2.4.5
17
+ rvm: 2.4.9
@@ -1,3 +1,9 @@
1
+ 2.5.2
2
+ -----
3
+
4
+ * Allow unit values to be declared in the unit system through aliases and not just the base unit name.
5
+ * Fix some deprecations in tests and CI.
6
+
1
7
  2.5.1
2
8
  ----
3
9
 
@@ -14,12 +14,12 @@ class Measured::Unit
14
14
  @unit_system = unit_system
15
15
  end
16
16
 
17
- def with_unit_system(unit_system)
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
 
@@ -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.with_unit_system(self) }
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|
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Measured
3
- VERSION = "2.5.1"
3
+ VERSION = "2.5.2"
4
4
  end
@@ -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", "> 1.1.0"
26
+ spec.add_development_dependency "mocha", ">= 1.4.0"
27
27
  spec.add_development_dependency "pry"
28
28
  end
@@ -3,7 +3,7 @@ require "pry" unless ENV["CI"]
3
3
  require "measured"
4
4
  require "minitest/reporters"
5
5
  require "minitest/autorun"
6
- require "mocha/setup"
6
+ require "mocha/minitest"
7
7
 
8
8
  ActiveSupport.test_order = :random
9
9
 
@@ -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.1
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: 2019-07-12 00:00:00.000000000 Z
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.1.0
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.1.0
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
- rubyforge_project:
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