Improve type specifications and documentation
- Added missing type specifications for Hello function and rules - Updated documentation for the Deserialize protocol - Cleaned up IBAN validation function documentation - Enhanced test fixture generation with clearer parsing and error messages
This commit is contained in:
@@ -9,7 +9,7 @@ defmodule IbanEx.Country.Template do
|
||||
|
||||
@callback size() :: size()
|
||||
@callback rule() :: rule()
|
||||
@callback rules() :: []
|
||||
@callback rules() :: keyword()
|
||||
@callback rules_map() :: %{}
|
||||
@callback bban_fields() :: [atom()]
|
||||
@callback bban_size() :: non_neg_integer()
|
||||
@@ -66,7 +66,7 @@ def bban_fields(), do: rules_map() |> Map.keys()
|
||||
def rules_map(), do: rules() |> Map.new()
|
||||
|
||||
@impl IbanEx.Country.Template
|
||||
@spec rules() :: []
|
||||
@spec rules() :: keyword()
|
||||
def rules() do
|
||||
{rules, _bban_size} = calculate_rules()
|
||||
rules
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
defprotocol IbanEx.Deserialize do
|
||||
@moduledoc """
|
||||
Protocol for converting various data types into IBAN structs.
|
||||
|
||||
Implementations exist for String, Map, and List types.
|
||||
"""
|
||||
|
||||
@type iban() :: IbanEx.Iban.t()
|
||||
@type iban_or_error() ::
|
||||
iban()
|
||||
@@ -15,13 +21,8 @@ def to_iban(value)
|
||||
defimpl IbanEx.Deserialize, for: [BitString, String] do
|
||||
alias IbanEx.{Parser, Error}
|
||||
@type iban() :: IbanEx.Iban.t()
|
||||
@type iban_or_error() ::
|
||||
iban()
|
||||
| {:invalid_checksum, binary()}
|
||||
| {:invalid_format, binary()}
|
||||
| {:invalid_length, binary()}
|
||||
| {:can_not_parse_map, binary()}
|
||||
| {:unsupported_country_code, binary()}
|
||||
@type iban_or_error() :: iban() | {atom(), binary()}
|
||||
|
||||
def to_iban(string) do
|
||||
case Parser.parse(string) do
|
||||
{:ok, iban} -> iban
|
||||
|
||||
@@ -9,17 +9,12 @@ defmodule IbanEx.Parser do
|
||||
@type check_digits_string() :: <<_::16>>
|
||||
|
||||
@type iban() :: IbanEx.Iban.t()
|
||||
@type iban_or_error() ::
|
||||
{:ok, iban()}
|
||||
| {:invalid_checksum, binary()}
|
||||
| {:invalid_format, binary()}
|
||||
| {:invalid_length, binary()}
|
||||
| {:can_not_parse_map, binary()}
|
||||
| {:unsupported_country_code, binary()}
|
||||
@type iban_or_error() :: {:ok, iban()} | {:error, atom()}
|
||||
|
||||
@spec parse({:ok, binary()}) :: iban_or_error()
|
||||
def parse({:ok, iban_string}), do: parse(iban_string)
|
||||
|
||||
@spec parse(binary(), keyword()) :: iban_or_error()
|
||||
def parse(iban_string, options \\ [incomplete: false])
|
||||
|
||||
def parse(iban_string, incomplete: false) do
|
||||
@@ -70,6 +65,7 @@ def parse(iban_string, incomplete: true) do
|
||||
end
|
||||
|
||||
@spec parse_bban(binary(), <<_::16>>) :: map()
|
||||
@spec parse_bban(binary(), <<_::16>>, keyword()) :: map()
|
||||
def parse_bban(bban_string, country_code, options \\ [incomplete: false])
|
||||
|
||||
def parse_bban(bban_string, country_code, incomplete: true) do
|
||||
|
||||
@@ -101,7 +101,7 @@ defp size(iban) do
|
||||
|> String.length()
|
||||
end
|
||||
|
||||
# - Check whether a given IBAN violates the required format.
|
||||
@doc "Check whether a given IBAN violates the required format."
|
||||
@spec iban_violates_format?(String.t() | nil) :: boolean
|
||||
def iban_violates_format?(nil), do: true
|
||||
|
||||
@@ -119,21 +119,21 @@ def iban_violates_format?(iban) when is_binary(iban) do
|
||||
has_invalid_chars or country_code_lowercase
|
||||
end
|
||||
|
||||
# - Check whether a given IBAN violates the required format in bank_code.
|
||||
@doc "Check whether a given IBAN violates the required format in bank_code."
|
||||
@spec iban_violates_bank_code_format?(binary()) :: boolean
|
||||
def iban_violates_bank_code_format?(iban), do: iban_violates_bban_part_format?(iban, :bank_code)
|
||||
|
||||
# - Check whether a given IBAN violates the required format in branch_code.
|
||||
@doc "Check whether a given IBAN violates the required format in branch_code."
|
||||
@spec iban_violates_branch_code_format?(binary()) :: boolean
|
||||
def iban_violates_branch_code_format?(iban),
|
||||
do: iban_violates_bban_part_format?(iban, :branch_code)
|
||||
|
||||
# - Check whether a given IBAN violates the required format in account_number.
|
||||
@doc "Check whether a given IBAN violates the required format in account_number."
|
||||
@spec iban_violates_account_number_format?(binary()) :: boolean
|
||||
def iban_violates_account_number_format?(iban),
|
||||
do: iban_violates_bban_part_format?(iban, :account_number)
|
||||
|
||||
# - Check whether a given IBAN violates the required format in national_check.
|
||||
@doc "Check whether a given IBAN violates the required format in national_check."
|
||||
@spec iban_violates_national_check_format?(binary()) :: boolean
|
||||
def iban_violates_national_check_format?(iban),
|
||||
do: iban_violates_bban_part_format?(iban, :national_check)
|
||||
@@ -150,7 +150,7 @@ defp iban_violates_bban_part_format?(iban, part) do
|
||||
end
|
||||
end
|
||||
|
||||
# - Check whether a given IBAN violates the supported countries.
|
||||
@doc "Check whether a given IBAN violates the supported countries."
|
||||
@spec iban_unsupported_country?(String.t()) :: boolean
|
||||
def iban_unsupported_country?(iban) do
|
||||
supported? =
|
||||
|
||||
Reference in New Issue
Block a user