Initial commit

This commit is contained in:
2024-03-05 06:02:58 -05:00
commit a32c7a5b74
42 changed files with 1395 additions and 0 deletions

34
lib/iban_ex/country/at.ex Normal file
View File

@@ -0,0 +1,34 @@
defmodule IbanEx.Country.AT do
@moduledoc """
Austria IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@size 20
@rule ~r/^(?<bank_code>[0-9]{5})(?<account_number>[0-9]{11})$/i
@spec size() :: 20
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

36
lib/iban_ex/country/be.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule IbanEx.Country.BE do
@moduledoc """
Belgium IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@size 16
@rule ~r/^(?<bank_code>[0-9]{3})(?<account_number>[0-9]{7})(?<national_check>[0-9]{2})$/i
@spec size() :: 16
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, national_check]
|> Enum.join(joiner)
end
end

36
lib/iban_ex/country/bg.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule IbanEx.Country.BG do
@moduledoc """
Bulgaria IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@size 22
@rule ~r/^(?<bank_code>[A-Z]{4})(?<branch_code>[0-9]{4})(?<account_number>[0-9]{2}[0-9A-Z]{8})$/i
@spec size() :: 22
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, branch_code, account_number]
|> Enum.join(joiner)
end
end

34
lib/iban_ex/country/ch.ex Normal file
View File

@@ -0,0 +1,34 @@
defmodule IbanEx.Country.CH do
@moduledoc """
Switzerland IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@size 21
@rule ~r/^(?<bank_code>[0-9]{5})(?<account_number>[0-9A-Z]{12})$/i
@spec size() :: 21
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

36
lib/iban_ex/country/cy.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule IbanEx.Country.CY do
@moduledoc """
Cyprus IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@size 28
@rule ~r/^(?<bank_code>[0-9]{3})(?<branch_code>[0-9]{5})(?<account_number>[0-9A-Z]{16})$/i
@spec size() :: 28
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, branch_code, account_number]
|> Enum.join(joiner)
end
end

36
lib/iban_ex/country/cz.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule IbanEx.Country.CZ do
@moduledoc """
Czech Republic IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@size 24
@rule ~r/^(?<bank_code>[0-9]{4})(?<account_number>[0-9]{16})$/i
@spec size() :: 24
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

36
lib/iban_ex/country/de.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule IbanEx.Country.DE do
@moduledoc """
Germany IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@size 22
@rule ~r/^(?<bank_code>[0-9]{8})(?<account_number>[0-9]{10})$/i
@spec size() :: 22
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

36
lib/iban_ex/country/dk.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule IbanEx.Country.DK do
@moduledoc """
Denmark IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@size 18
@rule ~r/^(?<bank_code>[0-9]{4})(?<account_number>[0-9]{10})$/i
@spec size() :: 18
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

36
lib/iban_ex/country/ee.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule IbanEx.Country.EE do
@moduledoc """
Estonian IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@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
@spec size() :: 20
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, branch_code, account_number, national_check]
|> Enum.join(joiner)
end
end

36
lib/iban_ex/country/es.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule IbanEx.Country.ES do
@moduledoc """
Spain IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@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
@spec size() :: 24
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, branch_code, national_check, account_number]
|> Enum.join(joiner)
end
end

36
lib/iban_ex/country/fi.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule IbanEx.Country.FI do
@moduledoc """
Finland IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@size 18
@rule ~r/^(?<bank_code>[0-9]{6})(?<account_number>[0-9]{7})(?<national_check>[0-9]{1})$/i
@spec size() :: 18
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, national_check]
|> Enum.join(joiner)
end
end

36
lib/iban_ex/country/fr.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule IbanEx.Country.FR do
@moduledoc """
France IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@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
@spec size() :: 27
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, branch_code, account_number, national_check]
|> Enum.join(joiner)
end
end

35
lib/iban_ex/country/gb.ex Normal file
View File

@@ -0,0 +1,35 @@
defmodule IbanEx.Country.GB do
@moduledoc """
United Kingdom IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@size 22
@rule ~r/^(?<bank_code>[A-Z]{4})(?<branch_code>[0-9]{6})(?<account_number>[0-9]{8})$/i
@spec size() :: 22
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,
account_number: account_number
} = _iban,
joiner \\ " "
) do
[country_code, check_digits, bank_code, branch_code, account_number]
|> Enum.join(joiner)
end
end

36
lib/iban_ex/country/hr.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule IbanEx.Country.HR do
@moduledoc """
Croatia IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@size 21
@rule ~r/^(?<bank_code>[0-9]{7})(?<account_number>[0-9]{10})$/i
@spec size() :: 21
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

36
lib/iban_ex/country/lt.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule IbanEx.Country.LT do
@moduledoc """
Lithuanian IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@size 20
@rule ~r/^(?<bank_code>[0-9]{5})(?<account_number>[0-9]{11})$/i
@spec size() :: 20
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

36
lib/iban_ex/country/lu.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule IbanEx.Country.LU do
@moduledoc """
Luxembourg IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@size 20
@rule ~r/^(?<bank_code>[0-9]{3})(?<account_number>[0-9A-Z]{13})$/i
@spec size() :: 20
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

36
lib/iban_ex/country/lv.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule IbanEx.Country.LV do
@moduledoc """
Latvian IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@size 21
@rule ~r/^(?<bank_code>[A-Z]{4})(?<account_number>[0-9A-Z]{13})$/i
@spec size() :: 21
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

36
lib/iban_ex/country/mt.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule IbanEx.Country.MT do
@moduledoc """
Malta IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@size 31
@rule ~r/^(?<bank_code>[A-Z]{4})(?<branch_code>[0-9]{5})(?<account_number>[0-9A-Z]{18})$/i
@spec size() :: 31
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, branch_code, account_number]
|> Enum.join(joiner)
end
end

36
lib/iban_ex/country/nl.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule IbanEx.Country.NL do
@moduledoc """
Netherlands IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@size 18
@rule ~r/^(?<bank_code>[A-Z]{4})(?<account_number>[0-9]{10})$/i
@spec size() :: 18
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

36
lib/iban_ex/country/pl.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule IbanEx.Country.PL do
@moduledoc """
Poland IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@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
@spec size() :: 28
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, branch_code, national_check, account_number]
|> Enum.join(joiner)
end
end

36
lib/iban_ex/country/pt.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule IbanEx.Country.PT do
@moduledoc """
Portugal IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@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
@spec size() :: 25
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,
account_number: account_number,
national_check: national_check
} = _iban,
joiner \\ " "
) do
[country_code, check_digits, bank_code, branch_code, account_number, national_check]
|> Enum.join(joiner)
end
end

View File

@@ -0,0 +1,12 @@
defmodule IbanEx.Country.Template do
alias IbanEx.Iban
@type size() :: non_neg_integer()
@type rule() :: Regex.t()
@type country_code() :: <<_::16>> | atom()
@type joiner() :: String.t()
@callback size() :: size()
@callback rule() :: rule()
@callback to_s(Iban.t(), joiner()) :: String.t()
@callback to_s(Iban.t()) :: String.t()
end

36
lib/iban_ex/country/ua.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule IbanEx.Country.UA do
@moduledoc """
Ukrainian IBAN parsing rules
"""
alias IbanEx.Iban
@behaviour IbanEx.Country.Template
@size 29
@rule ~r/^(?<bank_code>[0-9]{6})(?<account_number>[0-9A-Z]{19})$/i
@spec size() :: 29
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