Added new countries

This commit is contained in:
2025-11-29 23:08:52 -05:00
parent 858439713a
commit d197a86454
21 changed files with 849 additions and 10 deletions

View File

@@ -11,71 +11,107 @@ defmodule IbanEx.Country do
"AE" => IbanEx.Country.AE,
"AL" => IbanEx.Country.AL,
"AT" => IbanEx.Country.AT,
"AX" => IbanEx.Country.FI,
"AZ" => IbanEx.Country.AZ,
"BA" => IbanEx.Country.BA,
"BE" => IbanEx.Country.BE,
"BG" => IbanEx.Country.BG,
"BH" => IbanEx.Country.BH,
"BI" => IbanEx.Country.BI,
"BL" => IbanEx.Country.FR,
"BR" => IbanEx.Country.BR,
"BY" => IbanEx.Country.BY,
"CH" => IbanEx.Country.CH,
"CR" => IbanEx.Country.CR,
"CY" => IbanEx.Country.CY,
"CZ" => IbanEx.Country.CZ,
"DE" => IbanEx.Country.DE,
"DO" => IbanEx.Country.DO,
"DJ" => IbanEx.Country.DJ,
"DK" => IbanEx.Country.DK,
"DO" => IbanEx.Country.DO,
"EE" => IbanEx.Country.EE,
"ES" => IbanEx.Country.ES,
"EG" => IbanEx.Country.EG,
"ES" => IbanEx.Country.ES,
"FI" => IbanEx.Country.FI,
"FR" => IbanEx.Country.FR,
"FK" => IbanEx.Country.FK,
"FO" => IbanEx.Country.FO,
"FR" => IbanEx.Country.FR,
"GB" => IbanEx.Country.GB,
"GE" => IbanEx.Country.GE,
"GF" => IbanEx.Country.FR,
"GG" => IbanEx.Country.GB,
"GI" => IbanEx.Country.GI,
"GL" => IbanEx.Country.GL,
"GP" => IbanEx.Country.FR,
"GR" => IbanEx.Country.GR,
"GT" => IbanEx.Country.GT,
"HN" => IbanEx.Country.HN,
"HR" => IbanEx.Country.HR,
"HU" => IbanEx.Country.HU,
"IE" => IbanEx.Country.IE,
"IL" => IbanEx.Country.IL,
"IT" => IbanEx.Country.IT,
"IM" => IbanEx.Country.GB,
"IQ" => IbanEx.Country.IQ,
"IS" => IbanEx.Country.IS,
"IT" => IbanEx.Country.IT,
"JE" => IbanEx.Country.GB,
"JO" => IbanEx.Country.JO,
"KZ" => IbanEx.Country.KZ,
"KW" => IbanEx.Country.KW,
"KZ" => IbanEx.Country.KZ,
"LB" => IbanEx.Country.LB,
"LC" => IbanEx.Country.LC,
"LI" => IbanEx.Country.LI,
"LT" => IbanEx.Country.LT,
"LU" => IbanEx.Country.LU,
"LV" => IbanEx.Country.LV,
"LY" => IbanEx.Country.LY,
"MC" => IbanEx.Country.MC,
"MD" => IbanEx.Country.MD,
"ME" => IbanEx.Country.ME,
"MF" => IbanEx.Country.FR,
"MK" => IbanEx.Country.MK,
"MN" => IbanEx.Country.MN,
"MQ" => IbanEx.Country.FR,
"MR" => IbanEx.Country.MR,
"MT" => IbanEx.Country.MT,
"MU" => IbanEx.Country.MU,
"NC" => IbanEx.Country.FR,
"NI" => IbanEx.Country.NI,
"NL" => IbanEx.Country.NL,
"NO" => IbanEx.Country.NO,
"PL" => IbanEx.Country.PL,
"PT" => IbanEx.Country.PT,
"OM" => IbanEx.Country.OM,
"PF" => IbanEx.Country.FR,
"PK" => IbanEx.Country.PK,
"PL" => IbanEx.Country.PL,
"PM" => IbanEx.Country.FR,
"PS" => IbanEx.Country.PS,
"PT" => IbanEx.Country.PT,
"QA" => IbanEx.Country.QA,
"RE" => IbanEx.Country.FR,
"RO" => IbanEx.Country.RO,
"RS" => IbanEx.Country.RS,
"RU" => IbanEx.Country.RU,
"SA" => IbanEx.Country.SA,
"SC" => IbanEx.Country.SC,
"SD" => IbanEx.Country.SD,
"SE" => IbanEx.Country.SE,
"SI" => IbanEx.Country.SI,
"SK" => IbanEx.Country.SK,
"SM" => IbanEx.Country.SM,
"SO" => IbanEx.Country.SO,
"ST" => IbanEx.Country.ST,
"SV" => IbanEx.Country.SV,
"TF" => IbanEx.Country.FR,
"TL" => IbanEx.Country.TL,
"TN" => IbanEx.Country.TN,
"TR" => IbanEx.Country.TR,
"UA" => IbanEx.Country.UA,
"VA" => IbanEx.Country.VA,
"VG" => IbanEx.Country.VG,
"XK" => IbanEx.Country.XK
"WF" => IbanEx.Country.FR,
"XK" => IbanEx.Country.XK,
"YE" => IbanEx.Country.YE,
"YT" => IbanEx.Country.FR
}
@supported_country_codes Map.keys(@supported_countries)
@@ -93,6 +129,7 @@ def supported_country_modules(), do: @supported_country_modules
@spec country_module(country_code) :: module() | error_tuple()
def country_module(country_code) when is_binary(country_code) or is_atom(country_code) do
normalized_country_code = normalize(country_code)
case is_country_code_supported?(normalized_country_code) do
true -> supported_countries()[normalized_country_code]
_ -> {:error, :unsupported_country_code}
@@ -100,6 +137,7 @@ def country_module(country_code) when is_binary(country_code) or is_atom(country
end
@spec is_country_code_supported?(country_code()) :: boolean()
def is_country_code_supported?(country_code) when is_binary(country_code) or is_atom(country_code),
do: Enum.member?(@supported_country_codes, normalize(country_code))
def is_country_code_supported?(country_code)
when is_binary(country_code) or is_atom(country_code),
do: Enum.member?(@supported_country_codes, normalize(country_code))
end

43
lib/iban_ex/country/bi.ex Normal file
View File

@@ -0,0 +1,43 @@
defmodule IbanEx.Country.BI do
@moduledoc """
Burundi IBAN parsing rules
## Examples
```elixir
iex> %IbanEx.Iban{
...> country_code: "BI",
...> check_digits: "42",
...> bank_code: "10000",
...> branch_code: "10001",
...> account_number: "00003320451",
...> national_check: "81"
...> }
...> |> IbanEx.Country.BI.to_string()
"BI 42 10000 10001 00003320451 81"
```
"""
@size 27
@rule ~r/^(?<bank_code>[0-9]{5})(?<branch_code>[0-9]{5})(?<account_number>[0-9]{11})(?<national_check>[0-9]{2})$/i
use 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,
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

39
lib/iban_ex/country/by.ex Normal file
View File

@@ -0,0 +1,39 @@
defmodule IbanEx.Country.BY do
@moduledoc """
Belarus IBAN parsing rules
## Examples
```elixir
iex> %IbanEx.Iban{
...> country_code: "BY",
...> check_digits: "13",
...> bank_code: "NBRB",
...> account_number: "3600900000002Z00AB00"
...> }
...> |> IbanEx.Country.BY.to_string()
"BY 13 NBRB 3600900000002Z00AB00"
```
"""
@size 28
@rule ~r/^(?<bank_code>[A-Z0-9]{4})(?<account_number>[0-9]{4}[A-Z0-9]{16})$/i
use 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,
account_number: account_number
} = _iban,
joiner \\ " "
) do
[country_code, check_digits, bank_code, account_number]
|> Enum.join(joiner)
end
end

43
lib/iban_ex/country/dj.ex Normal file
View File

@@ -0,0 +1,43 @@
defmodule IbanEx.Country.DJ do
@moduledoc """
Djibouti IBAN parsing rules
## Examples
```elixir
iex> %IbanEx.Iban{
...> country_code: "DJ",
...> check_digits: "21",
...> bank_code: "00010",
...> branch_code: "00000",
...> account_number: "01540001001",
...> national_check: "86"
...> }
...> |> IbanEx.Country.DJ.to_string()
"DJ 21 00010 00000 01540001001 86"
```
"""
@size 27
@rule ~r/^(?<bank_code>[0-9]{5})(?<branch_code>[0-9]{5})(?<account_number>[0-9]{11})(?<national_check>[0-9]{2})$/i
use 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,
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

39
lib/iban_ex/country/fk.ex Normal file
View File

@@ -0,0 +1,39 @@
defmodule IbanEx.Country.FK do
@moduledoc """
Falkland Islands (Malvinas) IBAN parsing rules
## Examples
```elixir
iex> %IbanEx.Iban{
...> country_code: "FK",
...> check_digits: "88",
...> bank_code: "SC",
...> account_number: "123456789012"
...> }
...> |> IbanEx.Country.FK.to_string()
"FK 88 SC 123456789012"
```
"""
@size 18
@rule ~r/^(?<bank_code>[A-Z]{2})(?<account_number>[0-9]{12})$/i
use 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,
account_number: account_number
} = _iban,
joiner \\ " "
) do
[country_code, check_digits, bank_code, account_number]
|> Enum.join(joiner)
end
end

39
lib/iban_ex/country/hn.ex Normal file
View File

@@ -0,0 +1,39 @@
defmodule IbanEx.Country.HN do
@moduledoc """
Honduras IBAN parsing rules
## Examples
```elixir
iex> %IbanEx.Iban{
...> country_code: "HN",
...> check_digits: "88",
...> bank_code: "CABF",
...> account_number: "00000000000250005469"
...> }
...> |> IbanEx.Country.HN.to_string()
"HN 88 CABF 00000000000250005469"
```
"""
@size 28
@rule ~r/^(?<bank_code>[A-Z]{4})(?<account_number>[0-9]{20})$/i
use 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,
account_number: account_number
} = _iban,
joiner \\ " "
) do
[country_code, check_digits, bank_code, account_number]
|> Enum.join(joiner)
end
end

41
lib/iban_ex/country/iq.ex Normal file
View File

@@ -0,0 +1,41 @@
defmodule IbanEx.Country.IQ do
@moduledoc """
Iraq IBAN parsing rules
## Examples
```elixir
iex> %IbanEx.Iban{
...> country_code: "IQ",
...> check_digits: "98",
...> bank_code: "NBIQ",
...> branch_code: "850",
...> account_number: "123456789012"
...> }
...> |> IbanEx.Country.IQ.to_string()
"IQ 98 NBIQ 850 123456789012"
```
"""
@size 23
@rule ~r/^(?<bank_code>[A-Z]{4})(?<branch_code>[0-9]{3})(?<account_number>[0-9]{12})$/i
use 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,
account_number: account_number
} = _iban,
joiner \\ " "
) do
[country_code, check_digits, bank_code, branch_code, account_number]
|> Enum.join(joiner)
end
end

39
lib/iban_ex/country/lc.ex Normal file
View File

@@ -0,0 +1,39 @@
defmodule IbanEx.Country.LC do
@moduledoc """
Saint Lucia IBAN parsing rules
## Examples
```elixir
iex> %IbanEx.Iban{
...> country_code: "LC",
...> check_digits: "55",
...> bank_code: "HEMM",
...> account_number: "000100010012001200023015"
...> }
...> |> IbanEx.Country.LC.to_string()
"LC 55 HEMM 000100010012001200023015"
```
"""
@size 32
@rule ~r/^(?<bank_code>[A-Z]{4})(?<account_number>[A-Z0-9]{24})$/i
use 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,
account_number: account_number
} = _iban,
joiner \\ " "
) do
[country_code, check_digits, bank_code, account_number]
|> Enum.join(joiner)
end
end

41
lib/iban_ex/country/ly.ex Normal file
View File

@@ -0,0 +1,41 @@
defmodule IbanEx.Country.LY do
@moduledoc """
Libya IBAN parsing rules
## Examples
```elixir
iex> %IbanEx.Iban{
...> country_code: "LY",
...> check_digits: "83",
...> bank_code: "002",
...> branch_code: "048",
...> account_number: "000020100120361"
...> }
...> |> IbanEx.Country.LY.to_string()
"LY 83 002 048 000020100120361"
```
"""
@size 25
@rule ~r/^(?<bank_code>[0-9]{3})(?<branch_code>[0-9]{3})(?<account_number>[0-9]{15})$/i
use 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,
account_number: account_number
} = _iban,
joiner \\ " "
) do
[country_code, check_digits, bank_code, branch_code, account_number]
|> Enum.join(joiner)
end
end

39
lib/iban_ex/country/mn.ex Normal file
View File

@@ -0,0 +1,39 @@
defmodule IbanEx.Country.MN do
@moduledoc """
Mongolia IBAN parsing rules
## Examples
```elixir
iex> %IbanEx.Iban{
...> country_code: "MN",
...> check_digits: "12",
...> bank_code: "1234",
...> account_number: "123456789123"
...> }
...> |> IbanEx.Country.MN.to_string()
"MN 12 1234 123456789123"
```
"""
@size 20
@rule ~r/^(?<bank_code>[0-9]{4})(?<account_number>[0-9]{12})$/i
use 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,
account_number: account_number
} = _iban,
joiner \\ " "
) do
[country_code, check_digits, bank_code, account_number]
|> Enum.join(joiner)
end
end

41
lib/iban_ex/country/mu.ex Normal file
View File

@@ -0,0 +1,41 @@
defmodule IbanEx.Country.MU do
@moduledoc """
Mauritius IBAN parsing rules
## Examples
```elixir
iex> %IbanEx.Iban{
...> country_code: "MU",
...> check_digits: "17",
...> bank_code: "BOMM01",
...> branch_code: "01",
...> account_number: "101030300200000MUR"
...> }
...> |> IbanEx.Country.MU.to_string()
"MU 17 BOMM01 01 101030300200000MUR"
```
"""
@size 30
@rule ~r/^(?<bank_code>[A-Z]{4}[0-9]{2})(?<branch_code>[0-9]{2})(?<account_number>[0-9]{12}[0-9]{3}[A-Z]{3})$/i
use 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,
account_number: account_number
} = _iban,
joiner \\ " "
) do
[country_code, check_digits, bank_code, branch_code, account_number]
|> Enum.join(joiner)
end
end

39
lib/iban_ex/country/ni.ex Normal file
View File

@@ -0,0 +1,39 @@
defmodule IbanEx.Country.NI do
@moduledoc """
Nicaragua IBAN parsing rules
## Examples
```elixir
iex> %IbanEx.Iban{
...> country_code: "NI",
...> check_digits: "45",
...> bank_code: "BAPR",
...> account_number: "00000013000003558124"
...> }
...> |> IbanEx.Country.NI.to_string()
"NI 45 BAPR 00000013000003558124"
```
"""
@size 28
@rule ~r/^(?<bank_code>[A-Z]{4})(?<account_number>[0-9]{20})$/i
use 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,
account_number: account_number
} = _iban,
joiner \\ " "
) do
[country_code, check_digits, bank_code, account_number]
|> Enum.join(joiner)
end
end

39
lib/iban_ex/country/om.ex Normal file
View File

@@ -0,0 +1,39 @@
defmodule IbanEx.Country.OM do
@moduledoc """
Oman IBAN parsing rules
## Examples
```elixir
iex> %IbanEx.Iban{
...> country_code: "OM",
...> check_digits: "81",
...> bank_code: "018",
...> account_number: "0000001299123456"
...> }
...> |> IbanEx.Country.OM.to_string()
"OM 81 018 0000001299123456"
```
"""
@size 23
@rule ~r/^(?<bank_code>[0-9]{3})(?<account_number>[A-Z0-9]{16})$/i
use 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,
account_number: account_number
} = _iban,
joiner \\ " "
) do
[country_code, check_digits, bank_code, account_number]
|> Enum.join(joiner)
end
end

26
lib/iban_ex/country/ps.ex Normal file
View File

@@ -0,0 +1,26 @@
defmodule IbanEx.Country.PS do
@moduledoc """
Palestine IBAN parsing rules
## Examples
```elixir
iex> %IbanEx.Iban{
...> country_code: "PS",
...> check_digits: "92",
...> bank_code: "PALS",
...> branch_code: nil,
...> national_check: nil,
...> account_number: "000000000400123456702"
...> }
...> |> IbanEx.Country.PS.to_string()
"PS 92 PALS 000000000400123456702"
```
"""
@size 29
@rule ~r/^(?<bank_code>[A-Z]{4})(?<account_number>[A-Z0-9]{21})$/i
use IbanEx.Country.Template
end

43
lib/iban_ex/country/ru.ex Normal file
View File

@@ -0,0 +1,43 @@
defmodule IbanEx.Country.RU do
@moduledoc """
Russia IBAN parsing rules
## Examples
```elixir
iex> %IbanEx.Iban{
...> country_code: "RU",
...> check_digits: "03",
...> bank_code: "044525225",
...> branch_code: "40817",
...> national_check: nil,
...> account_number: "810538091310419"
...> }
...> |> IbanEx.Country.RU.to_string()
"RU 03 044525225 40817 810538091310419"
```
"""
@size 33
@rule ~r/^(?<bank_code>[0-9]{9})(?<branch_code>[0-9]{5})(?<account_number>[A-Z0-9]{15})$/i
use 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,
account_number: account_number
} = _iban,
joiner \\ " "
) do
[country_code, check_digits, bank_code, branch_code, account_number]
|> Enum.join(joiner)
end
end

41
lib/iban_ex/country/sc.ex Normal file
View File

@@ -0,0 +1,41 @@
defmodule IbanEx.Country.SC do
@moduledoc """
Seychelles IBAN parsing rules
## Examples
```elixir
iex> %IbanEx.Iban{
...> country_code: "SC",
...> check_digits: "18",
...> bank_code: "SSCB11",
...> branch_code: "01",
...> account_number: "0000000000001497USD"
...> }
...> |> IbanEx.Country.SC.to_string()
"SC 18 SSCB11 01 0000000000001497USD"
```
"""
@size 31
@rule ~r/^(?<bank_code>[A-Z]{4}[0-9]{2})(?<branch_code>[0-9]{2})(?<account_number>[0-9]{16}[A-Z]{3})$/i
use 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,
account_number: account_number
} = _iban,
joiner \\ " "
) do
[country_code, check_digits, bank_code, branch_code, account_number]
|> Enum.join(joiner)
end
end

39
lib/iban_ex/country/sd.ex Normal file
View File

@@ -0,0 +1,39 @@
defmodule IbanEx.Country.SD do
@moduledoc """
Sudan IBAN parsing rules
## Examples
```elixir
iex> %IbanEx.Iban{
...> country_code: "SD",
...> check_digits: "21",
...> bank_code: "29",
...> account_number: "010501234001"
...> }
...> |> IbanEx.Country.SD.to_string()
"SD 21 29 010501234001"
```
"""
@size 18
@rule ~r/^(?<bank_code>[0-9]{2})(?<account_number>[0-9]{12})$/i
use 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,
account_number: account_number
} = _iban,
joiner \\ " "
) do
[country_code, check_digits, bank_code, account_number]
|> Enum.join(joiner)
end
end

43
lib/iban_ex/country/so.ex Normal file
View File

@@ -0,0 +1,43 @@
defmodule IbanEx.Country.SO do
@moduledoc """
Somalia IBAN parsing rules
## Examples
```elixir
iex> %IbanEx.Iban{
...> country_code: "SO",
...> check_digits: "21",
...> bank_code: "1000",
...> branch_code: "001",
...> national_check: nil,
...> account_number: "001000100141"
...> }
...> |> IbanEx.Country.SO.to_string()
"SO 21 1000 001 001000100141"
```
"""
@size 23
@rule ~r/^(?<bank_code>[0-9]{4})(?<branch_code>[0-9]{3})(?<account_number>[0-9]{12})$/i
use 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,
account_number: account_number
} = _iban,
joiner \\ " "
) do
[country_code, check_digits, bank_code, branch_code, account_number]
|> Enum.join(joiner)
end
end

43
lib/iban_ex/country/st.ex Normal file
View File

@@ -0,0 +1,43 @@
defmodule IbanEx.Country.ST do
@moduledoc """
Sao Tome and Principe IBAN parsing rules
## Examples
```elixir
iex> %IbanEx.Iban{
...> country_code: "ST",
...> check_digits: "23",
...> bank_code: "0001",
...> branch_code: "0001",
...> account_number: "00518453101",
...> national_check: "46"
...> }
...> |> IbanEx.Country.ST.to_string()
"ST 23 0001 0001 00518453101 46"
```
"""
@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
use 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,
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

43
lib/iban_ex/country/tn.ex Normal file
View File

@@ -0,0 +1,43 @@
defmodule IbanEx.Country.TN do
@moduledoc """
Tunisia IBAN parsing rules
## Examples
```elixir
iex> %IbanEx.Iban{
...> country_code: "TN",
...> check_digits: "59",
...> bank_code: "10",
...> branch_code: "006",
...> account_number: "0351835984788",
...> national_check: "31"
...> }
...> |> IbanEx.Country.TN.to_string()
"TN 59 10 006 0351835984788 31"
```
"""
@size 24
@rule ~r/^(?<bank_code>[0-9]{2})(?<branch_code>[0-9]{3})(?<account_number>[0-9]{13})(?<national_check>[0-9]{2})$/i
use 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,
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

41
lib/iban_ex/country/ye.ex Normal file
View File

@@ -0,0 +1,41 @@
defmodule IbanEx.Country.YE do
@moduledoc """
Yemen IBAN parsing rules
## Examples
```elixir
iex> %IbanEx.Iban{
...> country_code: "YE",
...> check_digits: "15",
...> bank_code: "CBYE",
...> branch_code: "0001",
...> account_number: "018861234567891234"
...> }
...> |> IbanEx.Country.YE.to_string()
"YE 15 CBYE 0001 018861234567891234"
```
"""
@size 30
@rule ~r/^(?<bank_code>[A-Z]{4})(?<branch_code>[0-9]{4})(?<account_number>[A-Z0-9]{18})$/i
use 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,
account_number: account_number
} = _iban,
joiner \\ " "
) do
[country_code, check_digits, bank_code, branch_code, account_number]
|> Enum.join(joiner)
end
end