diff --git a/lib/iban_ex/commons/commons.ex b/lib/iban_ex/commons/commons.ex index 713e9cb..243346f 100644 --- a/lib/iban_ex/commons/commons.ex +++ b/lib/iban_ex/commons/commons.ex @@ -1,4 +1,6 @@ defmodule IbanEx.Commons do + @moduledoc false + @spec normalize(binary()) :: binary() def normalize(string) do string diff --git a/lib/iban_ex/country.ex b/lib/iban_ex/country.ex index ab2d8ce..2a83641 100644 --- a/lib/iban_ex/country.ex +++ b/lib/iban_ex/country.ex @@ -1,4 +1,6 @@ defmodule IbanEx.Country do + @moduledoc false + import IbanEx.Commons, only: [normalize: 1] @type country_code() :: <<_::16>> | atom() diff --git a/lib/iban_ex/deserialize.ex b/lib/iban_ex/deserialize.ex index 38b4e70..9079917 100644 --- a/lib/iban_ex/deserialize.ex +++ b/lib/iban_ex/deserialize.ex @@ -7,8 +7,8 @@ end defimpl IbanEx.Deserialize, for: [BitString, String] do alias IbanEx.{Parser, Error} @type iban_or_error() :: IbanEx.Iban.t() | {:error, atom()} + @spec to_iban(binary()) :: iban_or_error() @spec to_iban(String.t()) :: iban_or_error() - @spec to_iban(binary()) :: IbanEx.Iban.t() def to_iban(string) do case Parser.parse(string) do {:ok, iban} -> iban diff --git a/lib/iban_ex/error.ex b/lib/iban_ex/error.ex index 7ff22d9..9012d45 100644 --- a/lib/iban_ex/error.ex +++ b/lib/iban_ex/error.ex @@ -1,7 +1,5 @@ defmodule IbanEx.Error do - @moduledoc """ - - """ + @moduledoc false @type error() :: :unsupported_country_code diff --git a/lib/iban_ex/formatter.ex b/lib/iban_ex/formatter.ex index cdb7421..9c4b7aa 100644 --- a/lib/iban_ex/formatter.ex +++ b/lib/iban_ex/formatter.ex @@ -1,4 +1,6 @@ defmodule IbanEx.Formatter do + @moduledoc false + alias IbanEx.Country import IbanEx.Commons, only: [normalize: 1] @@ -28,7 +30,7 @@ defmodule IbanEx.Formatter do def format(iban, :pretty) do country_module = Country.country_module(iban.country_code) - country_module.to_s(iban) + country_module.to_string(iban) end def format(iban, :splitted) do diff --git a/lib/iban_ex/iban.ex b/lib/iban_ex/iban.ex index 0443ca5..7a62e53 100644 --- a/lib/iban_ex/iban.ex +++ b/lib/iban_ex/iban.ex @@ -1,4 +1,6 @@ defmodule IbanEx.Iban do + @moduledoc false + alias IbanEx.Formatter alias IbanEx.{Serialize} diff --git a/lib/iban_ex/parser.ex b/lib/iban_ex/parser.ex index b2391cb..cc89647 100644 --- a/lib/iban_ex/parser.ex +++ b/lib/iban_ex/parser.ex @@ -1,4 +1,6 @@ defmodule IbanEx.Parser do + @moduledoc false + alias IbanEx.{Country, Iban, Validator} import IbanEx.Commons, only: [normalize_and_slice: 2] @@ -9,20 +11,27 @@ defmodule IbanEx.Parser do @spec parse({:ok, String.t()} | String.t()) :: iban_or_error() def parse({:ok, iban_string}), do: parse(iban_string) + def parse(iban_string) do - with {:ok, valid_iban} <- Validator.validate(iban_string) do - iban_map = %{ - country_code: country_code(valid_iban), - check_digits: check_digits(valid_iban), - } + case Validator.validate(iban_string) do + {:ok, valid_iban} -> + iban_map = %{ + country_code: country_code(valid_iban), + check_digits: check_digits(valid_iban) + } - regex = Country.country_module(iban_map.country_code).rule() - bban = bban(iban_string) - bban_map = for {key, val} <- Regex.named_captures(regex, bban), into: %{}, do: {String.to_atom(key), val} + regex = Country.country_module(iban_map.country_code).rule() + bban = bban(iban_string) - {:ok, struct(Iban, Map.merge(iban_map, bban_map))} - else - {:error, error_type} -> {:error, error_type} + bban_map = + for {key, val} <- Regex.named_captures(regex, bban), + into: %{}, + do: {String.to_atom(key), val} + + {:ok, struct(Iban, Map.merge(iban_map, bban_map))} + + {:error, error_type} -> + {:error, error_type} end end diff --git a/lib/iban_ex/serialize.ex b/lib/iban_ex/serialize.ex index 0a5e0fc..c7445fb 100644 --- a/lib/iban_ex/serialize.ex +++ b/lib/iban_ex/serialize.ex @@ -1,4 +1,6 @@ defmodule IbanEx.Serialize do + @moduledoc false + alias IbanEx.{Iban, Formatter} @spec to_string(Iban.t()) :: String.t() diff --git a/lib/iban_ex/validator/validator.ex b/lib/iban_ex/validator/validator.ex index ec7558a..e4d9caa 100644 --- a/lib/iban_ex/validator/validator.ex +++ b/lib/iban_ex/validator/validator.ex @@ -1,9 +1,11 @@ defmodule IbanEx.Validator do + @moduledoc false + alias IbanEx.{Country, Parser} alias IbanEx.Validator.Replacements import IbanEx.Commons, only: [normalize: 1] - @spec validate(String.t()) :: {:ok, String.t()} | {:error} + @spec validate(String.t()) :: {:ok, String.t()} | {:error, Atom.t()} def validate(iban) do cond do iban_violates_format?(iban) ->