Class: Worldwide::Units

Inherits:
Object
  • Object
show all
Defined in:
lib/worldwide/units.rb

Class Method Summary collapse

Class Method Details

.format(amount, unit, humanize: :short) ⇒ Object

Raises:

  • (ArgumentError)


58
59
60
61
62
63
64
65
66
# File 'lib/worldwide/units.rb', line 58

def format(amount, unit, humanize: :short)
  supported_humanization = SUPPORTED_HUMANIZATIONS[humanize.to_sym]
  raise ArgumentError, "Unsupported value for `humanize`: #{humanize}." unless supported_humanization

  measurement_key = MEASUREMENT_KEYS[unit.to_sym]
  raise ArgumentError, "Unsupported value for `unit`: #{unit}." unless measurement_key

  Cldr.t("units.unit_length.#{supported_humanization}.#{measurement_key}", count: amount)
end