Cldr.Unit.new
You're seeing just the function
new
, go back to Cldr.Unit module for more information.
Specs
new(unit() | value(), value() | unit(), Keyword.t()) :: {:ok, t()} | {:error, {module(), String.t()}}
Returns a new Unit.t
struct.
Arguments
unit
is any unit name returned byCldr.Unit.known_units/0
options
is Keyword list of options. The default is[]
Options
:usage
is the intended use of the unit. This is used during localization to convert the unit to that appropriate for the unit category, usage, target territory and unit value. The usage must be defined for the unit's category. SeeCldr.Unit.unit_category_usage/0
for the known usage types for each category.
Returns
unit
or{:error, {exception, message}}
Examples
iex> Cldr.Unit.new(23, :gallon)
{:ok, Cldr.Unit.new!(:gallon, 23)}
iex> Cldr.Unit.new(:gallon, 23)
{:ok, Cldr.Unit.new!(:gallon, 23)}
iex> Cldr.Unit.new(14, :gadzoots)
{:error, {Cldr.UnknownUnitError,
"Unknown unit was detected at \"gadzoots\""}}
Cldr.Unit.new(:gallon, 23, usage: :fluid)
#=> {:ok, #Cldr.Unit<:gallon, 23, usage: :fluid, format_options: []>}