View Source ElixirCLRut (ElixirCLRUT v1.0.3)

A module that helps with validation and formatting of chilean RUT/RUN identifiers. Made by the Elixir Chile Community.

Link to this section Summary

Functions

Gets the check digit of a rut

Cleans a RUT

Alternate name for checkdigit/2

Formats a string or Rut struct with the Rut format.

When given a string it will return an ElixirCLRut.Struct

Executes the rut validations.

Performs a simple validation and returns the boolean result. true if is valid.

Link to this section Functions

Link to this function

checkdigit(input, includes_checkdigit \\ true)

View Source

Gets the check digit of a rut

  • since: "1.0.3"
@spec clean(String.t()) :: String.t()

Cleans a RUT

  • since: "1.0.2"
Link to this function

dv(input, includes_checkdigit \\ true)

View Source

Alternate name for checkdigit/2

  • since: "1.0.3"
Link to this function

format(input, options \\ [dashed?: true, separator: "."])

View Source (since 1.0.1)
@spec format(struct() | String.t(), String.t() | boolean() | keyword()) :: String.t()

Formats a string or Rut struct with the Rut format.

examples

Examples

iex> format("1", false)
"1-9"

iex> format("K", false)
"K"

iex> format("63009482", true)
"6.300.948-2"

iex> format("6300948-2", dashed?: true, separator: ",")
"6,300,948-2"

iex> format("141231553")
"14.123.155-3"
Link to this function

from(input)

View Source (since 1.0.0)
@spec from(String.t()) :: struct()

When given a string it will return an ElixirCLRut.Struct

example

Example

iex> from("1-9")
%ElixirCLRut.Struct{checkdigit: "9", dashed?: true, from: "1-9", includes_checkdigit?: true, lastdigit: "9", normalized: [1], normalized_with_checkdigit: [1, 9]}

iex> from("141231553")
%ElixirCLRut.Struct{checkdigit: "3", dashed?: false, from: "141231553", includes_checkdigit?: true, lastdigit: "3", normalized: [1, 4, 1, 2, 3, 1, 5, 5], normalized_with_checkdigit: [1, 4, 1, 2, 3, 1, 5, 5, 3]}

iex> from("14123155", false)
%ElixirCLRut.Struct{checkdigit: "3", dashed?: false, from: "14123155", includes_checkdigit?: false, lastdigit: "3", normalized: [1, 4, 1, 2, 3, 1, 5, 5], normalized_with_checkdigit: [1, 4, 1, 2, 3, 1, 5, 5, 3]}

iex> from("20.961.605-K")
%ElixirCLRut.Struct{checkdigit: "K", dashed?: true, from: "20.961.605-K", includes_checkdigit?: true, lastdigit: "K", normalized: [2, 0, 9, 6, 1, 6, 0, 5], normalized_with_checkdigit: [2, 0, 9, 6, 1, 6, 0, 5, "K"]}
Link to this function

from(input, includes_check_digit)

View Source (since 1.0.2)
@spec from(String.t(), boolean()) :: struct()
Link to this function

valid(input, includes_checkdigit \\ true)

View Source (since 1.0.2)
@spec valid(struct() | String.t(), boolean()) :: struct()

Executes the rut validations.

examples

Examples

iex> valid("1-9").valid?
true

iex> valid("1").valid?
false

iex> valid("6300948-1").valid?
false
Link to this function

validate(input)

View Source (since 1.0.2)
@spec validate(struct() | String.t()) :: boolean()

Performs a simple validation and returns the boolean result. true if is valid.

examples

Examples

iex> validate("1-9")
true

iex> validate("1k-9")
false

iex> validate("6300948-1")
false

iex> validate(from("6300948-1"))
false