Bugfixes. Bump to 0.1.1

This commit is contained in:
Danil Negrienko 2024-12-13 00:34:25 -05:00
parent 695ffc31c5
commit a47e331b25
7 changed files with 33 additions and 31 deletions

View File

@ -9,7 +9,7 @@ The package can be installed by adding `ukraine_tax_id` to your list of dependen
```elixir
def deps do
[
{:ukraine_tax_id, "~> 0.1.0"}
{:ukraine_tax_id, "~> 0.1.1"}
]
end
```

View File

@ -1,6 +1,12 @@
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]
@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
quote do
@ -34,6 +40,7 @@ defmodule UkraineTaxidEx.BaseParser do
end
defp generate({:error, error}), do: {:error, error}
defp generate({:ok, string}), do: generate(string)
end
end
end

View File

@ -1,12 +1,12 @@
defmodule UkraineTaxidEx.BaseValidator do
@callback validate(String.t()) ::
{:ok, String.t()}
@callback validate(code :: String.t()) ::
{:ok, code :: String.t()}
| {:error,
:length_too_short | :length_too_long | :invalid_length | :invalid_checksum}
@callback violates_length?(String.t()) :: boolean
@callback violates_length_too_short?(String.t()) :: boolean
@callback violates_length_too_long?(String.t()) :: boolean
@callback violates_checksum?(String.t()) :: boolean
@callback violates_length?(code :: String.t()) :: boolean
@callback violates_length_too_short?(code :: String.t()) :: boolean
@callback violates_length_too_long?(code :: String.t()) :: boolean
@callback violates_checksum?(code :: String.t()) :: boolean
defmacro __using__(_) do
quote do
@ -31,28 +31,25 @@ defmodule UkraineTaxidEx.BaseValidator do
@doc "Check whether a given EDRPOU violates the required length"
@impl BaseValidator
@spec violates_length?(String.t()) :: boolean
def violates_length?(string),
do: String.length(string) != length()
@spec violates_length?(code :: String.t()) :: boolean
def violates_length?(code), do: String.length(code) != length()
@doc "Check whether a given EDRPOU too short"
@impl BaseValidator
@spec violates_length_too_short?(String.t()) :: boolean
def violates_length_too_short?(string),
do: String.length(string) < length()
@spec violates_length_too_short?(code :: String.t()) :: boolean
def violates_length_too_short?(code), do: String.length(code) < length()
@doc "Check whether a given EDRPOU too long"
@impl BaseValidator
@spec violates_length_too_long?(String.t()) :: boolean
def violates_length_too_long?(string),
do: String.length(string) > length()
@spec violates_length_too_long?(code :: String.t()) :: boolean
def violates_length_too_long?(code), do: String.length(code) > length()
@doc "Check whether a given EDRPOU has correct checksum"
@impl BaseValidator
@spec violates_checksum?(String.t()) :: boolean
def violates_checksum?(string) do
@spec violates_checksum?(code :: String.t()) :: boolean
def violates_checksum?(code) do
{digits, check_digit} =
string
code
|> digits()
|> digits_and_check_digit()

View File

@ -53,9 +53,7 @@ defmodule UkraineTaxidEx.Edrpou.Parser do
| :length_too_long
| :invalid_checksum}
defp generate({:error, error}), do: {:error, error}
defp generate({:ok, string}) do
defp generate(string) do
digits = digits(string)
%{code: string, check_sum: check_sum(digits), check_digit: check_digit(digits)}

View File

@ -2,20 +2,20 @@ defmodule UkraineTaxidEx.Itin.Error do
@type error() ::
:invalid_length
| :invalid_checksum
| :length_to_long
| :length_to_short
| :length_too_long
| :length_too_short
@type errors() :: [error()]
@errors [
:invalid_length,
:invalid_checksum,
:length_to_long,
:length_to_short
:length_too_long,
:length_too_short
]
@messages [
invalid_length: "ITIN violates the required length",
invalid_checksum: "ITIN checksum is invalid",
length_to_long: "ITIN longer then required length",
length_to_short: "ITIN shorter then required length"
length_too_long: "ITIN longer then required length",
length_too_short: "ITIN shorter then required length"
]
@spec message(error()) :: String.t()

View File

@ -59,7 +59,7 @@ defmodule UkraineTaxidEx.Itin.Parser do
use UkraineTaxidEx.BaseParser
defp generate({:ok, string}) do
defp generate(string) do
digits = digits(string)
%{

View File

@ -5,7 +5,7 @@ defmodule UkraineTaxidEx.MixProject do
@module UkraineTaxidEx
@source_url "https://g.tulz.dev/opensource/ukraine-taxid-ex"
@docs_url "https://hexdocs.pm/#{@app}"
@version "0.1.0"
@version "0.1.1"
def project do
[