ExKcal.Calc (ExKcal v0.0.8)

Provides functions to handle some of the operations related to weight manipulation on the ExKcal.Products.

Link to this section Summary

Types

Known SI prefixes.

Volume of substance and unit it is represented in.

Weight of substance and unit it is represented in.

Functions

Super quirky function adjusting amount of product. I bet there are mistakes, corner cases not being covered and calculation issues!

Converts ExKcal.Units.weight() and ExKcal.Units.volume() type values to target unit.

Link to this section Types

Specs

si_prefix() ::
  :Y
  | :Z
  | :E
  | :P
  | :T
  | :G
  | :M
  | :k
  | :h
  | :da
  | :d
  | :c
  | :m
  | :μ
  | :n
  | :p
  | :f
  | :a
  | :z
  | :y

Known SI prefixes.

Specs

volume() :: {float(), :l | :dl | :ml} | {nil, :none}

Volume of substance and unit it is represented in.

Specs

weight() :: {float(), :kg | :g | :mg | :μg} | {nil, :none}

Weight of substance and unit it is represented in.

Link to this section Functions

Link to this function

adjust_amount(value, arg, current_amount \\ nil)

Specs

adjust_amount(struct(), weight() | volume(), weight() | volume() | nil) ::
  struct()

Super quirky function adjusting amount of product. I bet there are mistakes, corner cases not being covered and calculation issues!

Link to this function

convert_si_unit(arg, unit_to)

Specs

convert_si_unit(weight() | volume(), atom()) :: weight() | volume()

Converts ExKcal.Units.weight() and ExKcal.Units.volume() type values to target unit.

Notes

There is some quirkiness to that function:

  • it converts from prefix to prefix, not really from unit to unit. This means that only prefix is taken into account during the conversion. Because of that, conversion between volume and weight units will go through (see examples).

Examples

iex> import ExKcal.Calc
iex> convert_si_unit({0.1, :mg}, :dl)
{0.001, :dl}
iex> convert_si_unit({1002.0, :g}, :kg)
{1.002, :kg}
iex> convert_si_unit({0.23, :dag}, :mg)
{2.3e3, :mg}