brdocs v0.2.0 BrDocs.Utils View Source

Utility module to hold all the calculations functions used to generate and validate data.

Link to this section Summary

Functions

Generates a string with random numbers

Generates a verification digit based on the value's length of the doc

Calculates the MOD11 verification digit of a value

Link to this section Functions

Link to this function

generate_random_numbers(size) View Source
generate_random_numbers(integer()) :: String.t()

Generates a string with random numbers.

Examples

iex> BrDocs.Utils.generate_random_numbers(3)
"599"

iex> BrDocs.Utils.generate_random_numbers(8)
"79052943"

iex> BrDocs.Utils.generate_random_numbers(12)
"064766405673"
Link to this function

make_digit(value) View Source
make_digit(String.t()) :: String.t()

Generates a verification digit based on the value's length of the doc.

Value's length

Examples

iex> BrDocs.Utils.make_digit("123456789")
"0"

iex> BrDocs.Utils.make_digit("1234567890")
"9"

iex> BrDocs.Utils.make_digit("114447770001")
"6"

iex> BrDocs.Utils.make_digit("1144477700016")
"1"
Link to this function

mod11(value, range) View Source
mod11(String.t(), [integer()]) :: integer()

Calculates the MOD11 verification digit of a value.

Range length must be the equals to the value length.

Examples

  iex> BrDocs.Utils.mod11("123", [1, 2, 3])
  8

  iex> BrDocs.Utils.mod11("111444777", [10, 9, 8, 7, 6, 5, 4, 3, 2])
  3

  iex> BrDocs.Utils.mod11("1114447773", [11, 10, 9, 8, 7, 6, 5, 4, 3, 2])
  5