weighable 0.3.0 → 0.4.0

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
  SHA1:
3
- metadata.gz: fb8d123fefcbe3daf695cb9dcf93e2e147c63695
4
- data.tar.gz: 8f9b0a8d24ba30ff273d26d7660e921dd63d60e3
3
+ metadata.gz: c03bc3a4ff0bfd00b9d109976a410d2f388655f5
4
+ data.tar.gz: 360fc90c09b6d6a7a6201ec7b145cac15f9d8f0c
5
5
  SHA512:
6
- metadata.gz: 0c43e2acb080c205130d21282ce342886dccefa651941c516d9eb73b3cb31c8861c683d1f2465cf0424a085ac9bc637477733a6be45dc9eb959b3ae01f60b594
7
- data.tar.gz: 38e06a95c686ca5cfef9fc47059be0c771bf8cdcc8820795faa94f27c7963f924c512c3e860417eb0fd0f830298bc8ba436ddbc9396cdd87bb6d7f330f1393b3
6
+ metadata.gz: 0b331cea39251b48e885f9a829f9bb843694c6bc111b11460dc31a40875255e3e4bdbb87fd8c4b953b370e4e4589d25f977bb928be1004f4221c9843fdf4a736
7
+ data.tar.gz: 851a333bb993776932edf2ee5109e08e87310ba0ae3d6b6e9db04d4babeec293c73b9e399904daf483e32839a86b2032c9242208fb9cc517e43799bcaa98b248
@@ -1,3 +1,3 @@
1
1
  module Weighable
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
@@ -22,6 +22,16 @@ module Weighable
22
22
  unit: nil
23
23
  }.freeze
24
24
 
25
+ ABBREVATION_ALIASES = {
26
+ 'g' => :gram,
27
+ 'oz' => :ounce,
28
+ 'lb' => :pound,
29
+ 'mg' => :milligram,
30
+ 'kg' => :kilogram,
31
+ 'ea' => :unit,
32
+ nil => :unit
33
+ }.freeze
34
+
25
35
  GRAMS_PER_OUNCE = BigDecimal.new('28.34952')
26
36
  GRAMS_PER_POUND = BigDecimal.new('453.59237')
27
37
  OUNCES_PER_POUND = BigDecimal.new('16')
@@ -78,7 +88,9 @@ module Weighable
78
88
 
79
89
  def self.parse(string)
80
90
  value, unit = string.split(' ')
81
- Weight.new(value, UNIT_ABBREVIATION.find { |_k, v| v == unit }.first)
91
+ unit = ABBREVATION_ALIASES[unit]
92
+ fail ArgumentError, 'invalid weight' if unit.nil?
93
+ Weight.new(value, unit)
82
94
  end
83
95
 
84
96
  def initialize(value, unit)
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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trae Robrock