# `Macaw.Format.Measure`
[🔗](https://github.com/dcoai/macaw_format/blob/v0.1.0/lib/macaw/format/measure.ex#L1)

A field's default format (spec/01 §6): how a measure's values are written with no
format given, built by `Macaw.Format.for_measure/2` and written by
`Macaw.Format.measure/2`.

It is data: the resolved measure, the way its values are written (`kind`), the d3
formats it writes their numbers with, each a `Macaw.Format`, and what its unit
resolves to (`units`): each conversion it writes values by, resolved once with
`Macaw.Units.Unit.conversion/2`, and each suffix it writes, so that writing a value
applies a conversion with `Macaw.Units.Unit.convert/2` and reads no unit code
(macaw_units spec/01 §5, macaw_data#459).

    iex> {:ok, bytes} = Macaw.Format.for_measure(%{unit: "By"})
    iex> {bytes.kind, Macaw.Format.measure(bytes, 1_500_000)}
    {:quantity, "1.50 MB"}

# `conversion`

```elixir
@type conversion() :: {Macaw.Units.Unit.exact(), {integer(), pos_integer()}} | nil
```

A conversion `Macaw.Units.Unit.conversion/2` resolved, or `nil` for a value written as
it is: the unit is the one written, or none, or the pair does not convert.

# `display`

```elixir
@type display() :: {conversion(), String.t()}
```

A unit a value is written in: the conversion into it and its suffix.

# `kind`

```elixir
@type kind() :: :duration | :currency | :ratio | :count | :quantity | :unit | :number
```

How a measure's values are written (spec/01 §6's table).

# `notation`

```elixir
@type notation() :: :auto | :plain | :grouped | :si | {:si, 3..24} | :fixed
```

A number's notation with no measure; `:fixed` is a precision given alone.

# `t`

```elixir
@type t() :: %Macaw.Format.Measure{
  currency:
    %{code: String.t(), symbol: String.t() | nil, amount: Macaw.Format.t()}
    | nil,
  fixed: Macaw.Format.t(),
  format: Macaw.Format.t() | nil,
  kind: kind(),
  locale: Macaw.Format.Locale.t(),
  measure: %{
    unit: Macaw.Units.Unit.code() | nil,
    quantity: Macaw.Units.Quantity.t() | nil
  },
  notation: notation(),
  precision: 0..20,
  style: :compound | :magnitude,
  system: :metric | :us | :uk | :as_posted,
  units: units()
}
```

# `units`

```elixir
@type units() :: %{
  optional(:suffix) =&gt; String.t(),
  optional(:seconds) =&gt; conversion(),
  optional(:percent) =&gt; conversion(),
  optional(:one) =&gt; conversion(),
  optional(:display) =&gt;
    {:one, display()} | {:ladder, [display(), ...], display()}
}
```

What the measure's unit resolves to, once, for its kind: `:suffix` the unit's own
suffix; `:seconds` a duration's conversion to `s`; `:percent` and `:one` a ratio's to
`%` and to `1`; `:display` a quantity's units, `{:one, display}` for a unit written in
one unit whatever the magnitude, else `{:ladder, members, zero}`, its family's members
smallest first and the one zero is written in.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
