”Use“ and some metaprograming to refactor behaviours implimentation
This commit is contained in:
parent
368225f331
commit
1a9d6758fd
|
@ -3,32 +3,8 @@ defmodule IbanEx.Country.AT do
|
||||||
Austria IBAN parsing rules
|
Austria IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 20
|
@size 20
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[0-9]{5})(?<account_number>[0-9]{11})$/i
|
@rule ~r/^(?<bank_code>[0-9]{5})(?<account_number>[0-9]{11})$/i
|
||||||
|
|
||||||
@spec size() :: 20
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
|
||||||
def rule(), do: @rule
|
|
||||||
|
|
||||||
@spec to_s(Iban.t()) :: binary()
|
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
|
||||||
country_code: country_code,
|
|
||||||
check_digits: check_digits,
|
|
||||||
bank_code: bank_code,
|
|
||||||
account_number: account_number
|
|
||||||
} = _iban,
|
|
||||||
joiner \\ " "
|
|
||||||
) do
|
|
||||||
[country_code, check_digits, bank_code, account_number]
|
|
||||||
|> Enum.join(joiner)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,23 +3,15 @@ defmodule IbanEx.Country.BE do
|
||||||
Belgium IBAN parsing rules
|
Belgium IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 16
|
@size 16
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<account_number>[0-9]{7})(?<national_check>[0-9]{2})$/i
|
@rule ~r/^(?<bank_code>[0-9]{3})(?<account_number>[0-9]{7})(?<national_check>[0-9]{2})$/i
|
||||||
|
|
||||||
@spec size() :: 16
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
@impl IbanEx.Country.Template
|
||||||
def rule(), do: @rule
|
@spec to_string(Iban.t()) :: binary()
|
||||||
|
@spec to_string(Iban.t(), binary()) :: binary()
|
||||||
@spec to_s(Iban.t()) :: binary()
|
def to_string(
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
%Iban{
|
||||||
country_code: country_code,
|
country_code: country_code,
|
||||||
check_digits: check_digits,
|
check_digits: check_digits,
|
||||||
|
|
|
@ -3,23 +3,17 @@ defmodule IbanEx.Country.BG do
|
||||||
Bulgaria IBAN parsing rules
|
Bulgaria IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 22
|
@size 22
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[A-Z]{4})(?<branch_code>[0-9]{4})(?<account_number>[0-9]{2}[0-9A-Z]{8})$/i
|
@rule ~r/^(?<bank_code>[A-Z]{4})(?<branch_code>[0-9]{4})(?<account_number>[0-9]{2}[0-9A-Z]{8})$/i
|
||||||
|
|
||||||
|
use IbanEx.Country.Template
|
||||||
|
|
||||||
@spec size() :: 22
|
@spec size() :: 22
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
@impl IbanEx.Country.Template
|
||||||
def rule(), do: @rule
|
@spec to_string(Iban.t()) :: binary()
|
||||||
|
@spec to_string(Iban.t(), binary()) :: binary()
|
||||||
@spec to_s(Iban.t()) :: binary()
|
def to_string(
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
%Iban{
|
||||||
country_code: country_code,
|
country_code: country_code,
|
||||||
check_digits: check_digits,
|
check_digits: check_digits,
|
||||||
|
|
|
@ -3,32 +3,8 @@ defmodule IbanEx.Country.CH do
|
||||||
Switzerland IBAN parsing rules
|
Switzerland IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 21
|
@size 21
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[0-9]{5})(?<account_number>[0-9A-Z]{12})$/i
|
@rule ~r/^(?<bank_code>[0-9]{5})(?<account_number>[0-9A-Z]{12})$/i
|
||||||
|
|
||||||
@spec size() :: 21
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
|
||||||
def rule(), do: @rule
|
|
||||||
|
|
||||||
@spec to_s(Iban.t()) :: binary()
|
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
|
||||||
country_code: country_code,
|
|
||||||
check_digits: check_digits,
|
|
||||||
bank_code: bank_code,
|
|
||||||
account_number: account_number
|
|
||||||
} = _iban,
|
|
||||||
joiner \\ " "
|
|
||||||
) do
|
|
||||||
[country_code, check_digits, bank_code, account_number]
|
|
||||||
|> Enum.join(joiner)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,23 +3,15 @@ defmodule IbanEx.Country.CY do
|
||||||
Cyprus IBAN parsing rules
|
Cyprus IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 28
|
@size 28
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<branch_code>[0-9]{5})(?<account_number>[0-9A-Z]{16})$/i
|
@rule ~r/^(?<bank_code>[0-9]{3})(?<branch_code>[0-9]{5})(?<account_number>[0-9A-Z]{16})$/i
|
||||||
|
|
||||||
@spec size() :: 28
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
@impl IbanEx.Country.Template
|
||||||
def rule(), do: @rule
|
@spec to_string(Iban.t()) :: binary()
|
||||||
|
@spec to_string(Iban.t(), binary()) :: binary()
|
||||||
@spec to_s(Iban.t()) :: binary()
|
def to_string(
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
%Iban{
|
||||||
country_code: country_code,
|
country_code: country_code,
|
||||||
check_digits: check_digits,
|
check_digits: check_digits,
|
||||||
|
|
|
@ -3,34 +3,8 @@ defmodule IbanEx.Country.CZ do
|
||||||
Czech Republic IBAN parsing rules
|
Czech Republic IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 24
|
@size 24
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[0-9]{4})(?<account_number>[0-9]{16})$/i
|
@rule ~r/^(?<bank_code>[0-9]{4})(?<account_number>[0-9]{16})$/i
|
||||||
|
|
||||||
@spec size() :: 24
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
|
||||||
def rule(), do: @rule
|
|
||||||
|
|
||||||
@spec to_s(Iban.t()) :: binary()
|
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
|
||||||
country_code: country_code,
|
|
||||||
check_digits: check_digits,
|
|
||||||
bank_code: bank_code,
|
|
||||||
branch_code: _branch_code,
|
|
||||||
national_check: _national_check,
|
|
||||||
account_number: account_number
|
|
||||||
} = _iban,
|
|
||||||
joiner \\ " "
|
|
||||||
) do
|
|
||||||
[country_code, check_digits, bank_code, account_number]
|
|
||||||
|> Enum.join(joiner)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,34 +3,8 @@ defmodule IbanEx.Country.DE do
|
||||||
Germany IBAN parsing rules
|
Germany IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 22
|
@size 22
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[0-9]{8})(?<account_number>[0-9]{10})$/i
|
@rule ~r/^(?<bank_code>[0-9]{8})(?<account_number>[0-9]{10})$/i
|
||||||
|
|
||||||
@spec size() :: 22
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
|
||||||
def rule(), do: @rule
|
|
||||||
|
|
||||||
@spec to_s(Iban.t()) :: binary()
|
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
|
||||||
country_code: country_code,
|
|
||||||
check_digits: check_digits,
|
|
||||||
bank_code: bank_code,
|
|
||||||
branch_code: _branch_code,
|
|
||||||
national_check: _national_check,
|
|
||||||
account_number: account_number
|
|
||||||
} = _iban,
|
|
||||||
joiner \\ " "
|
|
||||||
) do
|
|
||||||
[country_code, check_digits, bank_code, account_number]
|
|
||||||
|> Enum.join(joiner)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,35 +2,8 @@ defmodule IbanEx.Country.DK do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Denmark IBAN parsing rules
|
Denmark IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 18
|
@size 18
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[0-9]{4})(?<account_number>[0-9]{10})$/i
|
@rule ~r/^(?<bank_code>[0-9]{4})(?<account_number>[0-9]{10})$/i
|
||||||
|
|
||||||
@spec size() :: 18
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
|
||||||
def rule(), do: @rule
|
|
||||||
|
|
||||||
@spec to_s(Iban.t()) :: binary()
|
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
|
||||||
country_code: country_code,
|
|
||||||
check_digits: check_digits,
|
|
||||||
bank_code: bank_code,
|
|
||||||
branch_code: _branch_code,
|
|
||||||
national_check: _national_check,
|
|
||||||
account_number: account_number
|
|
||||||
} = _iban,
|
|
||||||
joiner \\ " "
|
|
||||||
) do
|
|
||||||
[country_code, check_digits, bank_code, account_number]
|
|
||||||
|> Enum.join(joiner)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,23 +3,15 @@ defmodule IbanEx.Country.EE do
|
||||||
Estonian IBAN parsing rules
|
Estonian IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 20
|
@size 20
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[0-9]{2})(?<branch_code>[0-9]{2})(?<account_number>[0-9]{11})(?<national_check>[0-9]{1})$/i
|
@rule ~r/^(?<bank_code>[0-9]{2})(?<branch_code>[0-9]{2})(?<account_number>[0-9]{11})(?<national_check>[0-9]{1})$/i
|
||||||
|
|
||||||
@spec size() :: 20
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
@impl IbanEx.Country.Template
|
||||||
def rule(), do: @rule
|
@spec to_string(Iban.t()) :: binary()
|
||||||
|
@spec to_string(Iban.t(), binary()) :: binary()
|
||||||
@spec to_s(Iban.t()) :: binary()
|
def to_string(
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
%Iban{
|
||||||
country_code: country_code,
|
country_code: country_code,
|
||||||
check_digits: check_digits,
|
check_digits: check_digits,
|
||||||
|
|
|
@ -3,23 +3,15 @@ defmodule IbanEx.Country.ES do
|
||||||
Spain IBAN parsing rules
|
Spain IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 24
|
@size 24
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[0-9]{4})(?<branch_code>[0-9]{4})(?<national_check>[0-9]{2})(?<account_number>[0-9]{10})$/i
|
@rule ~r/^(?<bank_code>[0-9]{4})(?<branch_code>[0-9]{4})(?<national_check>[0-9]{2})(?<account_number>[0-9]{10})$/i
|
||||||
|
|
||||||
@spec size() :: 24
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
@impl IbanEx.Country.Template
|
||||||
def rule(), do: @rule
|
@spec to_string(Iban.t()) :: binary()
|
||||||
|
@spec to_string(Iban.t(), binary()) :: binary()
|
||||||
@spec to_s(Iban.t()) :: binary()
|
def to_string(
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
%Iban{
|
||||||
country_code: country_code,
|
country_code: country_code,
|
||||||
check_digits: check_digits,
|
check_digits: check_digits,
|
||||||
|
|
|
@ -3,23 +3,15 @@ defmodule IbanEx.Country.FI do
|
||||||
Finland IBAN parsing rules
|
Finland IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 18
|
@size 18
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[0-9]{6})(?<account_number>[0-9]{7})(?<national_check>[0-9]{1})$/i
|
@rule ~r/^(?<bank_code>[0-9]{6})(?<account_number>[0-9]{7})(?<national_check>[0-9]{1})$/i
|
||||||
|
|
||||||
@spec size() :: 18
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
@impl IbanEx.Country.Template
|
||||||
def rule(), do: @rule
|
@spec to_string(Iban.t()) :: binary()
|
||||||
|
@spec to_string(Iban.t(), binary()) :: binary()
|
||||||
@spec to_s(Iban.t()) :: binary()
|
def to_string(
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
%Iban{
|
||||||
country_code: country_code,
|
country_code: country_code,
|
||||||
check_digits: check_digits,
|
check_digits: check_digits,
|
||||||
|
|
|
@ -3,23 +3,15 @@ defmodule IbanEx.Country.FR do
|
||||||
France IBAN parsing rules
|
France IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 27
|
@size 27
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[0-9]{5})(?<branch_code>[0-9]{5})(?<account_number>[0-9A-Z]{11})(?<national_check>[0-9]{2})$/i
|
@rule ~r/^(?<bank_code>[0-9]{5})(?<branch_code>[0-9]{5})(?<account_number>[0-9A-Z]{11})(?<national_check>[0-9]{2})$/i
|
||||||
|
|
||||||
@spec size() :: 27
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
@impl IbanEx.Country.Template
|
||||||
def rule(), do: @rule
|
@spec to_string(Iban.t()) :: binary()
|
||||||
|
@spec to_string(Iban.t(), binary()) :: binary()
|
||||||
@spec to_s(Iban.t()) :: binary()
|
def to_string(
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
%Iban{
|
||||||
country_code: country_code,
|
country_code: country_code,
|
||||||
check_digits: check_digits,
|
check_digits: check_digits,
|
||||||
|
|
|
@ -3,23 +3,15 @@ defmodule IbanEx.Country.GB do
|
||||||
United Kingdom IBAN parsing rules
|
United Kingdom IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 22
|
@size 22
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[A-Z]{4})(?<branch_code>[0-9]{6})(?<account_number>[0-9]{8})$/i
|
@rule ~r/^(?<bank_code>[A-Z]{4})(?<branch_code>[0-9]{6})(?<account_number>[0-9]{8})$/i
|
||||||
|
|
||||||
@spec size() :: 22
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
@impl IbanEx.Country.Template
|
||||||
def rule(), do: @rule
|
@spec to_string(Iban.t()) :: binary()
|
||||||
|
@spec to_string(Iban.t(), binary()) :: binary()
|
||||||
@spec to_s(Iban.t()) :: binary()
|
def to_string(
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
%Iban{
|
||||||
country_code: country_code,
|
country_code: country_code,
|
||||||
check_digits: check_digits,
|
check_digits: check_digits,
|
||||||
|
|
|
@ -3,34 +3,8 @@ defmodule IbanEx.Country.HR do
|
||||||
Croatia IBAN parsing rules
|
Croatia IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 21
|
@size 21
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[0-9]{7})(?<account_number>[0-9]{10})$/i
|
@rule ~r/^(?<bank_code>[0-9]{7})(?<account_number>[0-9]{10})$/i
|
||||||
|
|
||||||
@spec size() :: 21
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
|
||||||
def rule(), do: @rule
|
|
||||||
|
|
||||||
@spec to_s(Iban.t()) :: binary()
|
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
|
||||||
country_code: country_code,
|
|
||||||
check_digits: check_digits,
|
|
||||||
bank_code: bank_code,
|
|
||||||
branch_code: _branch_code,
|
|
||||||
national_check: _national_check,
|
|
||||||
account_number: account_number
|
|
||||||
} = _iban,
|
|
||||||
joiner \\ " "
|
|
||||||
) do
|
|
||||||
[country_code, check_digits, bank_code, account_number]
|
|
||||||
|> Enum.join(joiner)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,34 +3,8 @@ defmodule IbanEx.Country.LT do
|
||||||
Lithuanian IBAN parsing rules
|
Lithuanian IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 20
|
@size 20
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[0-9]{5})(?<account_number>[0-9]{11})$/i
|
@rule ~r/^(?<bank_code>[0-9]{5})(?<account_number>[0-9]{11})$/i
|
||||||
|
|
||||||
@spec size() :: 20
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
|
||||||
def rule(), do: @rule
|
|
||||||
|
|
||||||
@spec to_s(Iban.t()) :: binary()
|
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
|
||||||
country_code: country_code,
|
|
||||||
check_digits: check_digits,
|
|
||||||
bank_code: bank_code,
|
|
||||||
branch_code: _branch_code,
|
|
||||||
national_check: _national_check,
|
|
||||||
account_number: account_number
|
|
||||||
} = _iban,
|
|
||||||
joiner \\ " "
|
|
||||||
) do
|
|
||||||
[country_code, check_digits, bank_code, account_number]
|
|
||||||
|> Enum.join(joiner)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,34 +3,8 @@ defmodule IbanEx.Country.LU do
|
||||||
Luxembourg IBAN parsing rules
|
Luxembourg IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 20
|
@size 20
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<account_number>[0-9A-Z]{13})$/i
|
@rule ~r/^(?<bank_code>[0-9]{3})(?<account_number>[0-9A-Z]{13})$/i
|
||||||
|
|
||||||
@spec size() :: 20
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
|
||||||
def rule(), do: @rule
|
|
||||||
|
|
||||||
@spec to_s(Iban.t()) :: binary()
|
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
|
||||||
country_code: country_code,
|
|
||||||
check_digits: check_digits,
|
|
||||||
bank_code: bank_code,
|
|
||||||
branch_code: _branch_code,
|
|
||||||
national_check: _national_check,
|
|
||||||
account_number: account_number
|
|
||||||
} = _iban,
|
|
||||||
joiner \\ " "
|
|
||||||
) do
|
|
||||||
[country_code, check_digits, bank_code, account_number]
|
|
||||||
|> Enum.join(joiner)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,34 +3,8 @@ defmodule IbanEx.Country.LV do
|
||||||
Latvian IBAN parsing rules
|
Latvian IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 21
|
@size 21
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[A-Z]{4})(?<account_number>[0-9A-Z]{13})$/i
|
@rule ~r/^(?<bank_code>[A-Z]{4})(?<account_number>[0-9A-Z]{13})$/i
|
||||||
|
|
||||||
@spec size() :: 21
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
|
||||||
def rule(), do: @rule
|
|
||||||
|
|
||||||
@spec to_s(Iban.t()) :: binary()
|
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
|
||||||
country_code: country_code,
|
|
||||||
check_digits: check_digits,
|
|
||||||
bank_code: bank_code,
|
|
||||||
branch_code: _branch_code,
|
|
||||||
national_check: _national_check,
|
|
||||||
account_number: account_number
|
|
||||||
} = _iban,
|
|
||||||
joiner \\ " "
|
|
||||||
) do
|
|
||||||
[country_code, check_digits, bank_code, account_number]
|
|
||||||
|> Enum.join(joiner)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,23 +3,15 @@ defmodule IbanEx.Country.MT do
|
||||||
Malta IBAN parsing rules
|
Malta IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 31
|
@size 31
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[A-Z]{4})(?<branch_code>[0-9]{5})(?<account_number>[0-9A-Z]{18})$/i
|
@rule ~r/^(?<bank_code>[A-Z]{4})(?<branch_code>[0-9]{5})(?<account_number>[0-9A-Z]{18})$/i
|
||||||
|
|
||||||
@spec size() :: 31
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
@impl IbanEx.Country.Template
|
||||||
def rule(), do: @rule
|
@spec to_string(Iban.t()) :: binary()
|
||||||
|
@spec to_string(Iban.t(), binary()) :: binary()
|
||||||
@spec to_s(Iban.t()) :: binary()
|
def to_string(
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
%Iban{
|
||||||
country_code: country_code,
|
country_code: country_code,
|
||||||
check_digits: check_digits,
|
check_digits: check_digits,
|
||||||
|
|
|
@ -3,34 +3,8 @@ defmodule IbanEx.Country.NL do
|
||||||
Netherlands IBAN parsing rules
|
Netherlands IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 18
|
@size 18
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[A-Z]{4})(?<account_number>[0-9]{10})$/i
|
@rule ~r/^(?<bank_code>[A-Z]{4})(?<account_number>[0-9]{10})$/i
|
||||||
|
|
||||||
@spec size() :: 18
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
|
||||||
def rule(), do: @rule
|
|
||||||
|
|
||||||
@spec to_s(Iban.t()) :: binary()
|
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
|
||||||
country_code: country_code,
|
|
||||||
check_digits: check_digits,
|
|
||||||
bank_code: bank_code,
|
|
||||||
branch_code: _branch_code,
|
|
||||||
national_check: _national_check,
|
|
||||||
account_number: account_number
|
|
||||||
} = _iban,
|
|
||||||
joiner \\ " "
|
|
||||||
) do
|
|
||||||
[country_code, check_digits, bank_code, account_number]
|
|
||||||
|> Enum.join(joiner)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,23 +3,15 @@ defmodule IbanEx.Country.PL do
|
||||||
Poland IBAN parsing rules
|
Poland IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 28
|
@size 28
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[0-9]{3})(?<branch_code>[0-9]{4})(?<national_check>[0-9]{1})(?<account_number>[0-9]{16})$/i
|
@rule ~r/^(?<bank_code>[0-9]{3})(?<branch_code>[0-9]{4})(?<national_check>[0-9]{1})(?<account_number>[0-9]{16})$/i
|
||||||
|
|
||||||
@spec size() :: 28
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
@impl IbanEx.Country.Template
|
||||||
def rule(), do: @rule
|
@spec to_string(Iban.t()) :: binary()
|
||||||
|
@spec to_string(Iban.t(), binary()) :: binary()
|
||||||
@spec to_s(Iban.t()) :: binary()
|
def to_string(
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
%Iban{
|
||||||
country_code: country_code,
|
country_code: country_code,
|
||||||
check_digits: check_digits,
|
check_digits: check_digits,
|
||||||
|
|
|
@ -3,23 +3,15 @@ defmodule IbanEx.Country.PT do
|
||||||
Portugal IBAN parsing rules
|
Portugal IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 25
|
@size 25
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[0-9]{4})(?<branch_code>[0-9]{4})(?<account_number>[0-9]{11})(?<national_check>[0-9]{2})$/i
|
@rule ~r/^(?<bank_code>[0-9]{4})(?<branch_code>[0-9]{4})(?<account_number>[0-9]{11})(?<national_check>[0-9]{2})$/i
|
||||||
|
|
||||||
@spec size() :: 25
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
@impl IbanEx.Country.Template
|
||||||
def rule(), do: @rule
|
@spec to_string(Iban.t()) :: binary()
|
||||||
|
@spec to_string(Iban.t(), binary()) :: binary()
|
||||||
@spec to_s(Iban.t()) :: binary()
|
def to_string(
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
%Iban{
|
||||||
country_code: country_code,
|
country_code: country_code,
|
||||||
check_digits: check_digits,
|
check_digits: check_digits,
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
defmodule IbanEx.Country.Template do
|
defmodule IbanEx.Country.Template do
|
||||||
|
@moduledoc false
|
||||||
|
|
||||||
alias IbanEx.Iban
|
alias IbanEx.Iban
|
||||||
@type size() :: non_neg_integer()
|
@type size() :: non_neg_integer()
|
||||||
@type rule() :: Regex.t()
|
@type rule() :: Regex.t()
|
||||||
|
@ -7,6 +9,41 @@ defmodule IbanEx.Country.Template do
|
||||||
|
|
||||||
@callback size() :: size()
|
@callback size() :: size()
|
||||||
@callback rule() :: rule()
|
@callback rule() :: rule()
|
||||||
@callback to_s(Iban.t(), joiner()) :: String.t()
|
@callback to_string(Iban.t(), joiner()) :: String.t()
|
||||||
@callback to_s(Iban.t()) :: String.t()
|
@callback to_string(Iban.t()) :: String.t()
|
||||||
|
|
||||||
|
defmacro __using__(_opts) do
|
||||||
|
quote do
|
||||||
|
alias IbanEx.Iban
|
||||||
|
@behaviour IbanEx.Country.Template
|
||||||
|
|
||||||
|
@impl IbanEx.Country.Template
|
||||||
|
@spec to_string(Iban.t()) :: binary()
|
||||||
|
@spec to_string(Iban.t(), binary()) :: binary()
|
||||||
|
def to_string(
|
||||||
|
%Iban{
|
||||||
|
country_code: country_code,
|
||||||
|
check_digits: check_digits,
|
||||||
|
bank_code: bank_code,
|
||||||
|
branch_code: _branch_code,
|
||||||
|
national_check: _national_check,
|
||||||
|
account_number: account_number
|
||||||
|
} = _iban,
|
||||||
|
joiner \\ " "
|
||||||
|
) do
|
||||||
|
[country_code, check_digits, bank_code, account_number]
|
||||||
|
|> Enum.join(joiner)
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl IbanEx.Country.Template
|
||||||
|
@spec size() :: Integer.t()
|
||||||
|
def size(), do: @size
|
||||||
|
|
||||||
|
@impl IbanEx.Country.Template
|
||||||
|
@spec rule() :: Regex.t()
|
||||||
|
def rule(), do: @rule
|
||||||
|
|
||||||
|
defoverridable to_string: 1, to_string: 2, size: 0, rule: 0
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,34 +3,8 @@ defmodule IbanEx.Country.UA do
|
||||||
Ukrainian IBAN parsing rules
|
Ukrainian IBAN parsing rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias IbanEx.Iban
|
|
||||||
|
|
||||||
@behaviour IbanEx.Country.Template
|
|
||||||
|
|
||||||
@size 29
|
@size 29
|
||||||
|
|
||||||
@rule ~r/^(?<bank_code>[0-9]{6})(?<account_number>[0-9A-Z]{19})$/i
|
@rule ~r/^(?<bank_code>[0-9]{6})(?<account_number>[0-9A-Z]{19})$/i
|
||||||
|
|
||||||
@spec size() :: 29
|
use IbanEx.Country.Template
|
||||||
def size(), do: @size
|
|
||||||
|
|
||||||
@spec rule() :: Regex.t()
|
|
||||||
def rule(), do: @rule
|
|
||||||
|
|
||||||
@spec to_s(Iban.t()) :: binary()
|
|
||||||
@spec to_s(Iban.t(), binary()) :: binary()
|
|
||||||
def to_s(
|
|
||||||
%Iban{
|
|
||||||
country_code: country_code,
|
|
||||||
check_digits: check_digits,
|
|
||||||
bank_code: bank_code,
|
|
||||||
branch_code: _branch_code,
|
|
||||||
national_check: _national_check,
|
|
||||||
account_number: account_number
|
|
||||||
} = _iban,
|
|
||||||
joiner \\ " "
|
|
||||||
) do
|
|
||||||
[country_code, check_digits, bank_code, account_number]
|
|
||||||
|> Enum.join(joiner)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue