ex_gtin v0.2.4 ExGtin.Validation 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
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
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
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"}
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"}
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
Generate 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"}
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"}
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
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
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