weighable 0.7.1 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b515e43906733fc0b27547dfbe6dc4d5eca9cc93
4
- data.tar.gz: 3753374a62b002904362ffcf2aaffe739a55b06c
3
+ metadata.gz: 041e5b084228b37677243615538ee113378e3194
4
+ data.tar.gz: b9cbe0b310dfdbaf188c84e30cc9746b21cd7ed6
5
5
  SHA512:
6
- metadata.gz: 6efbf87f525c9ef359ccf2f8905ef4494708b864048c29640a065e8b899e637be76d1e51e3199f93e1812b2ea1498b394f63a544bcdfd45d66aaa9a823ed198d
7
- data.tar.gz: b9db169b73fef0810675e1ff4d487f2e56d2d39c639c1d583f531e59ed0d6a2575810e0e17c048f763eba2a3af7f2a49cdcc2b5c50e4e000fd7358e5eb0a0356
6
+ metadata.gz: 533e20a981cd6f0b40fd9d45641190e7fe87e118684569f3cf1bf3cca5ab8364cd6446c2934175c79a6183e3b66fe1e6f05618d3fa2e8811cd14d3d0f4ba1a3b
7
+ data.tar.gz: 7099cd4139a11dc54261a80f51b251160474a3eb2a915f175b60c3ea6f3094245cb59ae13dca6b42b3f87835f2c889acde83e54c00f5e01f810206672ca973f7
@@ -1,3 +1,3 @@
1
1
  module Weighable
2
- VERSION = '0.7.1'.freeze
2
+ VERSION = '0.8.0'.freeze
3
3
  end
@@ -88,11 +88,21 @@ module Weighable
88
88
 
89
89
  def self.parse(string)
90
90
  value, unit = string.split(' ')
91
- unit = ABBREVIATION_ALIASES[unit]
91
+ from_value_and_unit(value, unit)
92
+ end
93
+
94
+ def self.from_value_and_unit(value, unit)
95
+ unit = parse_unit(unit)
92
96
  fail ArgumentError, 'invalid weight' if unit.nil? || value.nil?
93
97
  Weight.new(value, unit)
94
98
  end
95
99
 
100
+ def self.parse_unit(unit)
101
+ unit = ActiveSupport::Inflector.singularize(unit.downcase) unless unit.nil?
102
+ unit_symbol = unit ? unit.to_sym : unit
103
+ UNIT[unit_symbol] || ABBREVIATION_ALIASES[unit]
104
+ end
105
+
96
106
  def initialize(value, unit)
97
107
  @value = value.to_d
98
108
  @unit = unit.is_a?(Fixnum) ? unit : unit_from_symbol(unit.to_sym)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weighable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trae Robrock