Files
iban-ex/lib/iban_ex/country.ex

144 lines
4.5 KiB
Elixir
Raw Normal View History

2024-03-05 06:02:58 -05:00
defmodule IbanEx.Country do
@moduledoc false
2024-03-05 06:02:58 -05:00
import IbanEx.Commons, only: [normalize: 1]
@type country_code() :: <<_::16>> | atom()
@type error_tuple() :: {:error, atom()}
@supported_countries %{
2024-05-14 19:15:55 -04:00
"AD" => IbanEx.Country.AD,
"AE" => IbanEx.Country.AE,
"AL" => IbanEx.Country.AL,
2024-03-05 06:02:58 -05:00
"AT" => IbanEx.Country.AT,
2025-11-29 23:08:52 -05:00
"AX" => IbanEx.Country.FI,
2024-05-14 19:15:55 -04:00
"AZ" => IbanEx.Country.AZ,
"BA" => IbanEx.Country.BA,
2024-03-05 06:02:58 -05:00
"BE" => IbanEx.Country.BE,
"BG" => IbanEx.Country.BG,
2024-05-14 19:15:55 -04:00
"BH" => IbanEx.Country.BH,
2025-11-29 23:08:52 -05:00
"BI" => IbanEx.Country.BI,
"BL" => IbanEx.Country.FR,
2024-05-14 19:15:55 -04:00
"BR" => IbanEx.Country.BR,
2025-11-29 23:08:52 -05:00
"BY" => IbanEx.Country.BY,
2024-03-05 06:02:58 -05:00
"CH" => IbanEx.Country.CH,
2024-05-14 19:15:55 -04:00
"CR" => IbanEx.Country.CR,
2024-03-05 06:02:58 -05:00
"CY" => IbanEx.Country.CY,
"CZ" => IbanEx.Country.CZ,
"DE" => IbanEx.Country.DE,
2025-11-29 23:08:52 -05:00
"DJ" => IbanEx.Country.DJ,
2024-03-05 06:02:58 -05:00
"DK" => IbanEx.Country.DK,
2025-11-29 23:08:52 -05:00
"DO" => IbanEx.Country.DO,
2024-03-05 06:02:58 -05:00
"EE" => IbanEx.Country.EE,
2024-05-14 19:15:55 -04:00
"EG" => IbanEx.Country.EG,
2025-11-29 23:08:52 -05:00
"ES" => IbanEx.Country.ES,
2024-03-05 06:02:58 -05:00
"FI" => IbanEx.Country.FI,
2025-11-29 23:08:52 -05:00
"FK" => IbanEx.Country.FK,
2024-05-14 19:15:55 -04:00
"FO" => IbanEx.Country.FO,
2025-11-29 23:08:52 -05:00
"FR" => IbanEx.Country.FR,
2024-03-05 06:02:58 -05:00
"GB" => IbanEx.Country.GB,
2024-05-14 19:15:55 -04:00
"GE" => IbanEx.Country.GE,
2025-11-29 23:08:52 -05:00
"GF" => IbanEx.Country.FR,
"GG" => IbanEx.Country.GB,
"GI" => IbanEx.Country.GI,
2024-05-14 19:15:55 -04:00
"GL" => IbanEx.Country.GL,
2025-11-29 23:08:52 -05:00
"GP" => IbanEx.Country.FR,
"GR" => IbanEx.Country.GR,
2024-05-14 19:15:55 -04:00
"GT" => IbanEx.Country.GT,
2025-11-29 23:08:52 -05:00
"HN" => IbanEx.Country.HN,
2024-03-05 06:02:58 -05:00
"HR" => IbanEx.Country.HR,
"HU" => IbanEx.Country.HU,
"IE" => IbanEx.Country.IE,
2024-05-14 19:15:55 -04:00
"IL" => IbanEx.Country.IL,
2025-11-29 23:08:52 -05:00
"IM" => IbanEx.Country.GB,
"IQ" => IbanEx.Country.IQ,
"IS" => IbanEx.Country.IS,
2025-11-29 23:08:52 -05:00
"IT" => IbanEx.Country.IT,
"JE" => IbanEx.Country.GB,
2024-05-14 19:15:55 -04:00
"JO" => IbanEx.Country.JO,
"KW" => IbanEx.Country.KW,
2025-11-29 23:08:52 -05:00
"KZ" => IbanEx.Country.KZ,
2024-05-14 19:15:55 -04:00
"LB" => IbanEx.Country.LB,
2025-11-29 23:08:52 -05:00
"LC" => IbanEx.Country.LC,
"LI" => IbanEx.Country.LI,
2024-03-05 06:02:58 -05:00
"LT" => IbanEx.Country.LT,
"LU" => IbanEx.Country.LU,
"LV" => IbanEx.Country.LV,
2025-11-29 23:08:52 -05:00
"LY" => IbanEx.Country.LY,
"MC" => IbanEx.Country.MC,
2024-05-14 19:15:55 -04:00
"MD" => IbanEx.Country.MD,
"ME" => IbanEx.Country.ME,
2025-11-29 23:08:52 -05:00
"MF" => IbanEx.Country.FR,
2024-05-14 19:15:55 -04:00
"MK" => IbanEx.Country.MK,
2025-11-29 23:08:52 -05:00
"MN" => IbanEx.Country.MN,
"MQ" => IbanEx.Country.FR,
2024-05-14 19:15:55 -04:00
"MR" => IbanEx.Country.MR,
2024-03-05 06:02:58 -05:00
"MT" => IbanEx.Country.MT,
2025-11-29 23:08:52 -05:00
"MU" => IbanEx.Country.MU,
"NC" => IbanEx.Country.FR,
"NI" => IbanEx.Country.NI,
2024-03-05 06:02:58 -05:00
"NL" => IbanEx.Country.NL,
"NO" => IbanEx.Country.NO,
2025-11-29 23:08:52 -05:00
"OM" => IbanEx.Country.OM,
"PF" => IbanEx.Country.FR,
"PK" => IbanEx.Country.PK,
2024-03-05 06:02:58 -05:00
"PL" => IbanEx.Country.PL,
2025-11-29 23:08:52 -05:00
"PM" => IbanEx.Country.FR,
"PS" => IbanEx.Country.PS,
2024-03-05 06:02:58 -05:00
"PT" => IbanEx.Country.PT,
2024-05-14 19:15:55 -04:00
"QA" => IbanEx.Country.QA,
2025-11-29 23:08:52 -05:00
"RE" => IbanEx.Country.FR,
"RO" => IbanEx.Country.RO,
2024-05-14 19:15:55 -04:00
"RS" => IbanEx.Country.RS,
2025-11-29 23:08:52 -05:00
"RU" => IbanEx.Country.RU,
2024-05-14 19:15:55 -04:00
"SA" => IbanEx.Country.SA,
2025-11-29 23:08:52 -05:00
"SC" => IbanEx.Country.SC,
"SD" => IbanEx.Country.SD,
"SE" => IbanEx.Country.SE,
"SI" => IbanEx.Country.SI,
"SK" => IbanEx.Country.SK,
2024-05-14 19:15:55 -04:00
"SM" => IbanEx.Country.SM,
2025-11-29 23:08:52 -05:00
"SO" => IbanEx.Country.SO,
"ST" => IbanEx.Country.ST,
2024-05-14 19:15:55 -04:00
"SV" => IbanEx.Country.SV,
2025-11-29 23:08:52 -05:00
"TF" => IbanEx.Country.FR,
2024-05-14 19:15:55 -04:00
"TL" => IbanEx.Country.TL,
2025-11-29 23:08:52 -05:00
"TN" => IbanEx.Country.TN,
2024-05-14 19:15:55 -04:00
"TR" => IbanEx.Country.TR,
"UA" => IbanEx.Country.UA,
2024-05-14 19:15:55 -04:00
"VA" => IbanEx.Country.VA,
"VG" => IbanEx.Country.VG,
2025-11-29 23:08:52 -05:00
"WF" => IbanEx.Country.FR,
"XK" => IbanEx.Country.XK,
"YE" => IbanEx.Country.YE,
"YT" => IbanEx.Country.FR
2024-03-05 06:02:58 -05:00
}
@supported_country_codes Map.keys(@supported_countries)
@supported_country_modules Map.values(@supported_countries)
2024-03-05 06:02:58 -05:00
@spec supported_countries() :: map()
defp supported_countries(), do: @supported_countries
@spec supported_country_codes() :: [country_code()] | []
def supported_country_codes(), do: @supported_country_codes
@spec supported_country_modules() :: [module()] | []
def supported_country_modules(), do: @supported_country_modules
2024-05-14 19:15:55 -04:00
@spec country_module(country_code) :: module() | error_tuple()
2024-03-05 06:02:58 -05:00
def country_module(country_code) when is_binary(country_code) or is_atom(country_code) do
normalized_country_code = normalize(country_code)
2025-11-29 23:08:52 -05:00
2024-03-05 06:02:58 -05:00
case is_country_code_supported?(normalized_country_code) do
true -> supported_countries()[normalized_country_code]
_ -> {:error, :unsupported_country_code}
end
end
@spec is_country_code_supported?(country_code()) :: boolean()
2025-11-29 23:08:52 -05:00
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))
2024-03-05 06:02:58 -05:00
end