Module: PackwizardParser::GramConverter
- Defined in:
- lib/packwizard_parser/gram_converter.rb
Constant Summary collapse
- FACTORS =
Conversion factors for each unit to grams
{ 'g' => 1.0, 'kg' => 1000.0, 'oz' => 28.35, 'lb' => 453.59 }.freeze
Class Method Summary collapse
-
.convert(value:, unit:) ⇒ Float
Convert the value to grams.
Class Method Details
.convert(value:, unit:) ⇒ Float
Convert the value to grams
19 20 21 22 |
# File 'lib/packwizard_parser/gram_converter.rb', line 19 def self.convert(value:, unit:) factor = FACTORS.fetch(unit.to_s.downcase, 1.0) (value * factor) end |