Barlix.EAN13 (barlix v0.6.3) View Source

Implements EAN13.

Link to this section Summary

Functions

Encodes the given value using EAN13. The given code is validated first.

Accepts the same arguments as encode/1 but raises on error.

Validate an EAN13 code.

Link to this section Functions

Specs

encode(String.t()) :: {:error, String.t()} | {:ok, Barlix.code()}

Encodes the given value using EAN13. The given code is validated first.

Examples

iex> Barlix.EAN13.encode("5449000096241")
{:ok, {:D1, [
1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1
]}}

iex> Barlix.EAN13.encode("5901234123450")
{:error, "validation failed: expected checksum digit 7 but received 0"}

Specs

encode!(String.t()) :: Barlix.code() | no_return()

Accepts the same arguments as encode/1 but raises on error.

Specs

get_code([non_neg_integer()]) :: {:ok, Barlix.code()}

Specs

get_code(non_neg_integer(), [non_neg_integer()], [non_neg_integer()]) ::
  {:ok, Barlix.code()}

Specs

validate(String.t()) :: {:ok, [non_neg_integer()]} | {:error, String.t()}

Validate an EAN13 code.

Examples

iex> Barlix.EAN13.validate("5449000096241")
{:ok, [5, 4, 4, 9, 0, 0, 0, 0, 9, 6, 2, 4, 1]}

iex> Barlix.EAN13.validate("5901234123450")
{:error, "validation failed: expected checksum digit 7 but received 0"}