ex_uc v0.1.5-dev ExUc.Units
Units and conversion accessor
Allow efficient access to units and conversions defined in config.
Summary
Functions
Gets the conversion factor for the units
Gets the unit among its aliases that can be used as a key in conversions
Gets the kind of unit for ther given unit
Gets a map with every kind of unit defined in config
Functions
Gets the conversion factor for the units
If can find inverse relation when the conversion is a factor.
Returns Atom.t, Integer.t, Float.t
Parameters
- from: Atom representing the unit to convert from
- to: Atom representing the unit to convert to
Examples
iex>ExUc.Units.get_conversion(:g, :mg)
{:ok, 1000}
iex>ExUc.Units.get_conversion(:g, :zz)
{:error, "undetermined conversion"}
# This relation has not been defined but
# the inverse is based on a factor, so is valid.
iex>ExUc.Units.get_conversion(:km, :m)
{:ok, 1.0e3}
Gets the unit among its aliases that can be used as a key in conversions
Parameters
- alias: Atom with a unit aliases.
- kind: Atom or String for the kind where the alias is.
Examples
iex>ExUc.Units.get_key_alias(:meter, "length")
:m
iex>ExUc.Units.get_key_alias(:pounds, :mass)
:lb
iex>ExUc.Units.get_key_alias(:r4R3, :mass)
nil
Gets the kind of unit for ther given unit.
Parameters
- unit: Atom representing the unit to find the kind.
Examples
iex>ExUc.Units.get_kind(:kg)
"mass"
iex>ExUc.Units.get_kind(:meter)
"length"