ExGtin.Validation (ExGtin v1.1.0) View Source

Documentation for ExGtin. This library provides functionality for validating GTIN compliant codes.

Link to this section Summary

Functions

Checks the code for the proper length as specified by the GTIN-8,12,13,14 specification

Find the GS1 prefix country for a GTIN number

When generating the code, checks the code for the proper length as specified by the GTIN-8,12,13,14 specification. The code should be -1 the length of the GTIN code as the check digit will be added later

Generate check digit GTIN-8, GTIN-12, GTIN-13, GTIN-14, GSIN, SSCC codes

Generate valid GTIN-8, GTIN-12, GTIN-13, GTIN-14, GSIN, SSCC codes

Check for valid GTIN-8, GTIN-12, GTIN-13, GTIN-14, GSIN, SSCC codes

Looks up the GS1 prefix in a table GS1 Reference https://www.gs1.org/company-prefix

By index, returns the corresponding value to multiply the digit by

Calculates the sum of the digits in a string and multiplied value based on index order

Calculates the difference of the highest rounded multiple of 10

Link to this section Functions

Link to this function

check_code_length(number)

View Source (since 1.0.0)

Specs

check_code_length([number()]) :: {atom(), String.t()}

Checks the code for the proper length as specified by the GTIN-8,12,13,14 specification

Returns {atom, String.t()}

Examples

iex> ExGtin.Validation.check_code_length([1,2,3,4,5,6,7,8])
{:ok, "GTIN-8"}

iex> ExGtin.Validation.check_code_length([1,2,3,4,5,6,7])
{:error, "Invalid GTIN Code Length"}
Link to this function

find_gs1_prefix_country(number)

View Source (since 1.0.0)

Specs

find_gs1_prefix_country(String.t()) :: {atom(), String.t()}
find_gs1_prefix_country(number()) :: {atom(), String.t()}
find_gs1_prefix_country([number()]) :: {atom(), String.t()}

Find the GS1 prefix country for a GTIN number

Returns {atom, String.t()}

Examples

iex> ExGtin.Validation.find_gs1_prefix_country("53523235")
{:ok, "GS1 Malta"}

iex> ExGtin.Validation.find_gs1_prefix_country("6291041500214")
{:ok, "GS1 Emirates"}

iex> ExGtin.Validation.find_gs1_prefix_country("9541041500214")
{:error, "No GS1 prefix found"}
Link to this function

generate_check_code_length(number)

View Source (since 1.0.0)

Specs

generate_check_code_length([number()]) :: {atom(), String.t()}

When generating the code, checks the code for the proper length as specified by the GTIN-8,12,13,14 specification. The code should be -1 the length of the GTIN code as the check digit will be added later

Returns {atom, String.t()}

Examples

iex> ExGtin.Validation.generate_check_code_length([1,2,3,4,5,6,7])
{:ok, "GTIN-8"}

iex> ExGtin.Validation.generate_check_code_length([1,2,3,4,5,6])
{:error, "Invalid GTIN Code Length"}
Link to this function

generate_check_digit(number)

View Source (since 1.0.0)

Specs

generate_check_digit([number()]) :: number()

Generate check digit GTIN-8, GTIN-12, GTIN-13, GTIN-14, GSIN, SSCC codes

Returns number

Examples

iex> ExGtin.Validation.generate_check_digit([6,2,9,1,0,4,1,5,0,0,2,1])
3
Link to this function

generate_gtin_code(number)

View Source (since 1.0.0)

Specs

generate_gtin_code(String.t()) :: String.t() | {atom(), String.t()}
generate_gtin_code(number()) :: String.t() | {atom(), String.t()}
generate_gtin_code([number()]) :: String.t() | {atom(), String.t()}

Generate valid GTIN-8, GTIN-12, GTIN-13, GTIN-14, GSIN, SSCC codes

Returns {atom, String.t()}

Examples

iex> ExGtin.Validation.generate_gtin_code("629104150021")
{:ok, "6291041500213"}

iex> ExGtin.Validation.generate_gtin_code("62921")
{:error, "Invalid GTIN Code Length"}
Link to this function

gtin_check_digit(number)

View Source (since 1.0.0)

Specs

gtin_check_digit(String.t()) :: {atom(), String.t()}
gtin_check_digit(number()) :: {atom(), String.t()}
gtin_check_digit([number()]) :: {atom(), String.t()}

Check for valid GTIN-8, GTIN-12, GTIN-13, GTIN-14, GSIN, SSCC codes

Returns {atom, String.t()}

Examples

iex> ExGtin.Validation.gtin_check_digit("6291041500213")
{:ok, "GTIN-13"}

iex> ExGtin.Validation.gtin_check_digit("6291041500214")
{:error, "Invalid Code"}
Link to this function

lookup_gs1_prefix(number)

View Source (since 1.0.0)

Specs

lookup_gs1_prefix(integer()) :: {atom(), String.t()}

Looks up the GS1 prefix in a table GS1 Reference https://www.gs1.org/company-prefix

Returns {atom, String.t()}

Link to this function

mult_by_index_code(index)

View Source (since 1.0.0)

Specs

mult_by_index_code(number()) :: number()

By index, returns the corresponding value to multiply the digit by

Returns number

Examples

iex> ExGtin.Validation.mult_by_index_code(1)
1

iex> ExGtin.Validation.mult_by_index_code(2)
3
Link to this function

multiply_and_sum_array(numbers)

View Source (since 1.0.0)

Specs

multiply_and_sum_array([number()]) :: number()

Calculates the sum of the digits in a string and multiplied value based on index order

Returns number

Examples

iex> ExGtin.Validation.multiply_and_sum_array([6,2,9,1,0,4,1,5,0,0,2,1])
57
Link to this function

subtract_from_nearest_multiple_of_ten(number)

View Source (since 1.0.0)

Specs

subtract_from_nearest_multiple_of_ten(number()) :: number()

Calculates the difference of the highest rounded multiple of 10

Returns number

Examples

iex> ExGtin.Validation.subtract_from_nearest_multiple_of_ten(57)
3