Bugfixes. Bump to 0.1.1
This commit is contained in:
parent
695ffc31c5
commit
a47e331b25
|
@ -9,7 +9,7 @@ The package can be installed by adding `ukraine_tax_id` to your list of dependen
|
||||||
```elixir
|
```elixir
|
||||||
def deps do
|
def deps do
|
||||||
[
|
[
|
||||||
{:ukraine_tax_id, "~> 0.1.0"}
|
{:ukraine_tax_id, "~> 0.1.1"}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
defmodule UkraineTaxidEx.BaseParser do
|
defmodule UkraineTaxidEx.BaseParser do
|
||||||
|
@typedoc """
|
||||||
|
Options for parsing:
|
||||||
|
- `:normalize?` - if true, pad the string to the right length (8 for EDRPOU, 10 for ITIN)
|
||||||
|
- `:clean?` - if true, remove non-digit characters
|
||||||
|
"""
|
||||||
@type options :: [normalize?: boolean, clean?: boolean]
|
@type options :: [normalize?: boolean, clean?: boolean]
|
||||||
@callback parse(string :: String.t(), options :: options()) :: {:ok, term} | {:error, atom}
|
|
||||||
|
@callback parse(code :: String.t(), options :: options()) :: {:ok, term} | {:error, atom}
|
||||||
|
|
||||||
defmacro __using__(_) do
|
defmacro __using__(_) do
|
||||||
quote do
|
quote do
|
||||||
|
@ -34,6 +40,7 @@ defmodule UkraineTaxidEx.BaseParser do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp generate({:error, error}), do: {:error, error}
|
defp generate({:error, error}), do: {:error, error}
|
||||||
|
defp generate({:ok, string}), do: generate(string)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
defmodule UkraineTaxidEx.BaseValidator do
|
defmodule UkraineTaxidEx.BaseValidator do
|
||||||
@callback validate(String.t()) ::
|
@callback validate(code :: String.t()) ::
|
||||||
{:ok, String.t()}
|
{:ok, code :: String.t()}
|
||||||
| {:error,
|
| {:error,
|
||||||
:length_too_short | :length_too_long | :invalid_length | :invalid_checksum}
|
:length_too_short | :length_too_long | :invalid_length | :invalid_checksum}
|
||||||
@callback violates_length?(String.t()) :: boolean
|
@callback violates_length?(code :: String.t()) :: boolean
|
||||||
@callback violates_length_too_short?(String.t()) :: boolean
|
@callback violates_length_too_short?(code :: String.t()) :: boolean
|
||||||
@callback violates_length_too_long?(String.t()) :: boolean
|
@callback violates_length_too_long?(code :: String.t()) :: boolean
|
||||||
@callback violates_checksum?(String.t()) :: boolean
|
@callback violates_checksum?(code :: String.t()) :: boolean
|
||||||
|
|
||||||
defmacro __using__(_) do
|
defmacro __using__(_) do
|
||||||
quote do
|
quote do
|
||||||
|
@ -31,28 +31,25 @@ defmodule UkraineTaxidEx.BaseValidator do
|
||||||
|
|
||||||
@doc "Check whether a given EDRPOU violates the required length"
|
@doc "Check whether a given EDRPOU violates the required length"
|
||||||
@impl BaseValidator
|
@impl BaseValidator
|
||||||
@spec violates_length?(String.t()) :: boolean
|
@spec violates_length?(code :: String.t()) :: boolean
|
||||||
def violates_length?(string),
|
def violates_length?(code), do: String.length(code) != length()
|
||||||
do: String.length(string) != length()
|
|
||||||
|
|
||||||
@doc "Check whether a given EDRPOU too short"
|
@doc "Check whether a given EDRPOU too short"
|
||||||
@impl BaseValidator
|
@impl BaseValidator
|
||||||
@spec violates_length_too_short?(String.t()) :: boolean
|
@spec violates_length_too_short?(code :: String.t()) :: boolean
|
||||||
def violates_length_too_short?(string),
|
def violates_length_too_short?(code), do: String.length(code) < length()
|
||||||
do: String.length(string) < length()
|
|
||||||
|
|
||||||
@doc "Check whether a given EDRPOU too long"
|
@doc "Check whether a given EDRPOU too long"
|
||||||
@impl BaseValidator
|
@impl BaseValidator
|
||||||
@spec violates_length_too_long?(String.t()) :: boolean
|
@spec violates_length_too_long?(code :: String.t()) :: boolean
|
||||||
def violates_length_too_long?(string),
|
def violates_length_too_long?(code), do: String.length(code) > length()
|
||||||
do: String.length(string) > length()
|
|
||||||
|
|
||||||
@doc "Check whether a given EDRPOU has correct checksum"
|
@doc "Check whether a given EDRPOU has correct checksum"
|
||||||
@impl BaseValidator
|
@impl BaseValidator
|
||||||
@spec violates_checksum?(String.t()) :: boolean
|
@spec violates_checksum?(code :: String.t()) :: boolean
|
||||||
def violates_checksum?(string) do
|
def violates_checksum?(code) do
|
||||||
{digits, check_digit} =
|
{digits, check_digit} =
|
||||||
string
|
code
|
||||||
|> digits()
|
|> digits()
|
||||||
|> digits_and_check_digit()
|
|> digits_and_check_digit()
|
||||||
|
|
||||||
|
|
|
@ -53,9 +53,7 @@ defmodule UkraineTaxidEx.Edrpou.Parser do
|
||||||
| :length_too_long
|
| :length_too_long
|
||||||
| :invalid_checksum}
|
| :invalid_checksum}
|
||||||
|
|
||||||
defp generate({:error, error}), do: {:error, error}
|
defp generate(string) do
|
||||||
|
|
||||||
defp generate({:ok, string}) do
|
|
||||||
digits = digits(string)
|
digits = digits(string)
|
||||||
|
|
||||||
%{code: string, check_sum: check_sum(digits), check_digit: check_digit(digits)}
|
%{code: string, check_sum: check_sum(digits), check_digit: check_digit(digits)}
|
||||||
|
|
|
@ -2,20 +2,20 @@ defmodule UkraineTaxidEx.Itin.Error do
|
||||||
@type error() ::
|
@type error() ::
|
||||||
:invalid_length
|
:invalid_length
|
||||||
| :invalid_checksum
|
| :invalid_checksum
|
||||||
| :length_to_long
|
| :length_too_long
|
||||||
| :length_to_short
|
| :length_too_short
|
||||||
@type errors() :: [error()]
|
@type errors() :: [error()]
|
||||||
@errors [
|
@errors [
|
||||||
:invalid_length,
|
:invalid_length,
|
||||||
:invalid_checksum,
|
:invalid_checksum,
|
||||||
:length_to_long,
|
:length_too_long,
|
||||||
:length_to_short
|
:length_too_short
|
||||||
]
|
]
|
||||||
@messages [
|
@messages [
|
||||||
invalid_length: "ITIN violates the required length",
|
invalid_length: "ITIN violates the required length",
|
||||||
invalid_checksum: "ITIN checksum is invalid",
|
invalid_checksum: "ITIN checksum is invalid",
|
||||||
length_to_long: "ITIN longer then required length",
|
length_too_long: "ITIN longer then required length",
|
||||||
length_to_short: "ITIN shorter then required length"
|
length_too_short: "ITIN shorter then required length"
|
||||||
]
|
]
|
||||||
|
|
||||||
@spec message(error()) :: String.t()
|
@spec message(error()) :: String.t()
|
||||||
|
|
|
@ -59,7 +59,7 @@ defmodule UkraineTaxidEx.Itin.Parser do
|
||||||
|
|
||||||
use UkraineTaxidEx.BaseParser
|
use UkraineTaxidEx.BaseParser
|
||||||
|
|
||||||
defp generate({:ok, string}) do
|
defp generate(string) do
|
||||||
digits = digits(string)
|
digits = digits(string)
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
|
2
mix.exs
2
mix.exs
|
@ -5,7 +5,7 @@ defmodule UkraineTaxidEx.MixProject do
|
||||||
@module UkraineTaxidEx
|
@module UkraineTaxidEx
|
||||||
@source_url "https://g.tulz.dev/opensource/ukraine-taxid-ex"
|
@source_url "https://g.tulz.dev/opensource/ukraine-taxid-ex"
|
||||||
@docs_url "https://hexdocs.pm/#{@app}"
|
@docs_url "https://hexdocs.pm/#{@app}"
|
||||||
@version "0.1.0"
|
@version "0.1.1"
|
||||||
|
|
||||||
def project do
|
def project do
|
||||||
[
|
[
|
||||||
|
|
Loading…
Reference in New Issue