barlix v0.6.1 Barlix.EAN13 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

Link to this function

encode(value) View Source
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"}

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

Link to this function

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

Link to this function

validate(v) View Source
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"}