Class: UnitDatabase

baja. UnitDatabase


new UnitDatabase()

Queries the unit database from the station.

There is no reason to call this constructor directly; rather use the
static accessor functions.

Methods


<static> get( [callbacks])

Asynchronously retrieve the unit database from the station. The network
call to the station will only happen once: the same database instance will
be resolved no matter how many times this function is called.

Parameters:
Name Type Argument Description
callbacks Object <optional>
Properties
Name Type Argument Description
ok function <optional>

(Deprecated: use Promise) ok callback,
will receive a UnitDatabase instance populated with data retrieved from
the station

fail function <optional>

(Deprecated: use Promise) fail callback

batch baja.comm.Batch <optional>

batch to use for the network
request

Returns:
Type
Promise.<baja.UnitDatabase>

convertUnit(unitConversion, unit)

Convert a unit from metric to English or vice versa.

Parameters:
Name Type Description
unitConversion String | number | baja.FrozenEnum

metric to convert
from English to metric; english to convert from metric to English. Also
accepts baja:UnitConversion instances or ordinals.

unit baja.Unit

the unit to convert

Returns:

the converted unit. If the unit cannot be
converted, the same unit will be returned directly. If no unit given,
returns null.

Type
baja.Unit | null

getQuantities()

Get all quantities contained in the unit database.

Returns:
Type
Array.<baja.UnitDatabase.Quantity>

getUnit(name)

Retrieve the unit instance with the given name.

Parameters:
Name Type Description
name String | baja.Unit

the desired unit name. If a baja.Unit is
passed, it will just be returned back directly.

Returns:

the unit, or null if not found

Type
baja.Unit | null