BB.Unit (bb v0.13.0)
View SourceHelpers for working with units in BB DSLs.
Summary
Functions
Parse a string input as a unit.
Functions
@spec sigil_u( binary(), charlist() ) :: Cldr.Unit.t() | no_return()
Parse a string input as a unit.
The input should be a magnitude (integer or float) followed by a unit name. Whitespace between the magnitude and unit is optional.
Units are generally referred to in the singlular, even if it doesn't read as nicely, for example meter_per_second rather than meters_per_second. For a full list of supported units, see the
ex_cldr_units documentation.
Examples
Integer magnitudes:
iex> import BB.Unit
iex> ~u(5 meter)
Cldr.Unit.new!(:meter, 5)Float magnitudes:
iex> import BB.Unit
iex> ~u(0.1 meter)
Cldr.Unit.new!(Decimal.new("0.1"), :meter)Negative values:
iex> import BB.Unit
iex> ~u(-90 degree)
Cldr.Unit.new!(:degree, -90)Whitespace is optional:
iex> import BB.Unit
iex> ~u(100centimeter)
Cldr.Unit.new!(:centimeter, 100)Compound units:
iex> import BB.Unit
iex> ~u(10 meter_per_second)
Cldr.Unit.new!(:meter_per_second, 10)