From d197a8645498d0cc2aafb6450caa02770e422bb9 Mon Sep 17 00:00:00 2001 From: Danylo Negrienko Date: Sat, 29 Nov 2025 23:08:52 -0500 Subject: [PATCH] Added new countries --- lib/iban_ex/country.ex | 58 ++++++++++++++++++++++++++++++++------- lib/iban_ex/country/bi.ex | 43 +++++++++++++++++++++++++++++ lib/iban_ex/country/by.ex | 39 ++++++++++++++++++++++++++ lib/iban_ex/country/dj.ex | 43 +++++++++++++++++++++++++++++ lib/iban_ex/country/fk.ex | 39 ++++++++++++++++++++++++++ lib/iban_ex/country/hn.ex | 39 ++++++++++++++++++++++++++ lib/iban_ex/country/iq.ex | 41 +++++++++++++++++++++++++++ lib/iban_ex/country/lc.ex | 39 ++++++++++++++++++++++++++ lib/iban_ex/country/ly.ex | 41 +++++++++++++++++++++++++++ lib/iban_ex/country/mn.ex | 39 ++++++++++++++++++++++++++ lib/iban_ex/country/mu.ex | 41 +++++++++++++++++++++++++++ lib/iban_ex/country/ni.ex | 39 ++++++++++++++++++++++++++ lib/iban_ex/country/om.ex | 39 ++++++++++++++++++++++++++ lib/iban_ex/country/ps.ex | 26 ++++++++++++++++++ lib/iban_ex/country/ru.ex | 43 +++++++++++++++++++++++++++++ lib/iban_ex/country/sc.ex | 41 +++++++++++++++++++++++++++ lib/iban_ex/country/sd.ex | 39 ++++++++++++++++++++++++++ lib/iban_ex/country/so.ex | 43 +++++++++++++++++++++++++++++ lib/iban_ex/country/st.ex | 43 +++++++++++++++++++++++++++++ lib/iban_ex/country/tn.ex | 43 +++++++++++++++++++++++++++++ lib/iban_ex/country/ye.ex | 41 +++++++++++++++++++++++++++ 21 files changed, 849 insertions(+), 10 deletions(-) create mode 100644 lib/iban_ex/country/bi.ex create mode 100644 lib/iban_ex/country/by.ex create mode 100644 lib/iban_ex/country/dj.ex create mode 100644 lib/iban_ex/country/fk.ex create mode 100644 lib/iban_ex/country/hn.ex create mode 100644 lib/iban_ex/country/iq.ex create mode 100644 lib/iban_ex/country/lc.ex create mode 100644 lib/iban_ex/country/ly.ex create mode 100644 lib/iban_ex/country/mn.ex create mode 100644 lib/iban_ex/country/mu.ex create mode 100644 lib/iban_ex/country/ni.ex create mode 100644 lib/iban_ex/country/om.ex create mode 100644 lib/iban_ex/country/ps.ex create mode 100644 lib/iban_ex/country/ru.ex create mode 100644 lib/iban_ex/country/sc.ex create mode 100644 lib/iban_ex/country/sd.ex create mode 100644 lib/iban_ex/country/so.ex create mode 100644 lib/iban_ex/country/st.ex create mode 100644 lib/iban_ex/country/tn.ex create mode 100644 lib/iban_ex/country/ye.ex diff --git a/lib/iban_ex/country.ex b/lib/iban_ex/country.ex index 255105b..3050891 100644 --- a/lib/iban_ex/country.ex +++ b/lib/iban_ex/country.ex @@ -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 diff --git a/lib/iban_ex/country/bi.ex b/lib/iban_ex/country/bi.ex new file mode 100644 index 0000000..e7b33db --- /dev/null +++ b/lib/iban_ex/country/bi.ex @@ -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/^(?[0-9]{5})(?[0-9]{5})(?[0-9]{11})(?[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 diff --git a/lib/iban_ex/country/by.ex b/lib/iban_ex/country/by.ex new file mode 100644 index 0000000..3a36784 --- /dev/null +++ b/lib/iban_ex/country/by.ex @@ -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/^(?[A-Z0-9]{4})(?[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 diff --git a/lib/iban_ex/country/dj.ex b/lib/iban_ex/country/dj.ex new file mode 100644 index 0000000..f7b5e84 --- /dev/null +++ b/lib/iban_ex/country/dj.ex @@ -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/^(?[0-9]{5})(?[0-9]{5})(?[0-9]{11})(?[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 diff --git a/lib/iban_ex/country/fk.ex b/lib/iban_ex/country/fk.ex new file mode 100644 index 0000000..ae705bc --- /dev/null +++ b/lib/iban_ex/country/fk.ex @@ -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/^(?[A-Z]{2})(?[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 diff --git a/lib/iban_ex/country/hn.ex b/lib/iban_ex/country/hn.ex new file mode 100644 index 0000000..2f1f711 --- /dev/null +++ b/lib/iban_ex/country/hn.ex @@ -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/^(?[A-Z]{4})(?[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 diff --git a/lib/iban_ex/country/iq.ex b/lib/iban_ex/country/iq.ex new file mode 100644 index 0000000..981948b --- /dev/null +++ b/lib/iban_ex/country/iq.ex @@ -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/^(?[A-Z]{4})(?[0-9]{3})(?[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 diff --git a/lib/iban_ex/country/lc.ex b/lib/iban_ex/country/lc.ex new file mode 100644 index 0000000..e3e3575 --- /dev/null +++ b/lib/iban_ex/country/lc.ex @@ -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/^(?[A-Z]{4})(?[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 diff --git a/lib/iban_ex/country/ly.ex b/lib/iban_ex/country/ly.ex new file mode 100644 index 0000000..a68ce1e --- /dev/null +++ b/lib/iban_ex/country/ly.ex @@ -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/^(?[0-9]{3})(?[0-9]{3})(?[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 diff --git a/lib/iban_ex/country/mn.ex b/lib/iban_ex/country/mn.ex new file mode 100644 index 0000000..6f891c0 --- /dev/null +++ b/lib/iban_ex/country/mn.ex @@ -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/^(?[0-9]{4})(?[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 diff --git a/lib/iban_ex/country/mu.ex b/lib/iban_ex/country/mu.ex new file mode 100644 index 0000000..3ac63cb --- /dev/null +++ b/lib/iban_ex/country/mu.ex @@ -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/^(?[A-Z]{4}[0-9]{2})(?[0-9]{2})(?[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 diff --git a/lib/iban_ex/country/ni.ex b/lib/iban_ex/country/ni.ex new file mode 100644 index 0000000..9350d34 --- /dev/null +++ b/lib/iban_ex/country/ni.ex @@ -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/^(?[A-Z]{4})(?[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 diff --git a/lib/iban_ex/country/om.ex b/lib/iban_ex/country/om.ex new file mode 100644 index 0000000..b15da00 --- /dev/null +++ b/lib/iban_ex/country/om.ex @@ -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/^(?[0-9]{3})(?[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 diff --git a/lib/iban_ex/country/ps.ex b/lib/iban_ex/country/ps.ex new file mode 100644 index 0000000..2188c50 --- /dev/null +++ b/lib/iban_ex/country/ps.ex @@ -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/^(?[A-Z]{4})(?[A-Z0-9]{21})$/i + + use IbanEx.Country.Template +end + diff --git a/lib/iban_ex/country/ru.ex b/lib/iban_ex/country/ru.ex new file mode 100644 index 0000000..96d55c7 --- /dev/null +++ b/lib/iban_ex/country/ru.ex @@ -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/^(?[0-9]{9})(?[0-9]{5})(?[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 + diff --git a/lib/iban_ex/country/sc.ex b/lib/iban_ex/country/sc.ex new file mode 100644 index 0000000..e367cf2 --- /dev/null +++ b/lib/iban_ex/country/sc.ex @@ -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/^(?[A-Z]{4}[0-9]{2})(?[0-9]{2})(?[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 diff --git a/lib/iban_ex/country/sd.ex b/lib/iban_ex/country/sd.ex new file mode 100644 index 0000000..c99ec01 --- /dev/null +++ b/lib/iban_ex/country/sd.ex @@ -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/^(?[0-9]{2})(?[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 diff --git a/lib/iban_ex/country/so.ex b/lib/iban_ex/country/so.ex new file mode 100644 index 0000000..a1a0f71 --- /dev/null +++ b/lib/iban_ex/country/so.ex @@ -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/^(?[0-9]{4})(?[0-9]{3})(?[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 + diff --git a/lib/iban_ex/country/st.ex b/lib/iban_ex/country/st.ex new file mode 100644 index 0000000..b3e5f42 --- /dev/null +++ b/lib/iban_ex/country/st.ex @@ -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/^(?[0-9]{4})(?[0-9]{4})(?[0-9]{11})(?[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 diff --git a/lib/iban_ex/country/tn.ex b/lib/iban_ex/country/tn.ex new file mode 100644 index 0000000..8d6239b --- /dev/null +++ b/lib/iban_ex/country/tn.ex @@ -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/^(?[0-9]{2})(?[0-9]{3})(?[0-9]{13})(?[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 diff --git a/lib/iban_ex/country/ye.ex b/lib/iban_ex/country/ye.ex new file mode 100644 index 0000000..fa5f2ce --- /dev/null +++ b/lib/iban_ex/country/ye.ex @@ -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/^(?[A-Z]{4})(?[0-9]{4})(?[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