bban parse function

This commit is contained in:
2024-05-11 11:52:34 -04:00
parent ae17d13731
commit 4abf01b752
5 changed files with 29 additions and 12 deletions

View File

@@ -20,13 +20,10 @@ def parse(iban_string) do
check_digits: check_digits(valid_iban)
}
regex = Country.country_module(iban_map.country_code).rule()
bban = bban(iban_string)
bban_map =
for {key, val} <- Regex.named_captures(regex, bban),
into: %{},
do: {String.to_atom(key), val}
iban_string
|> bban()
|> parse_bban(iban_map.country_code)
{:ok, struct(Iban, Map.merge(iban_map, bban_map))}
@@ -35,6 +32,14 @@ def parse(iban_string) do
end
end
@spec parse_bban(binary(), <<_::16>>) :: map()
def parse_bban(bban_string, country_code) do
regex = Country.country_module(country_code).rule()
for {key, val} <- Regex.named_captures(regex, bban_string),
into: %{},
do: {String.to_atom(key), val}
end
@spec country_code(iban_string()) :: country_code_string()
def country_code(iban_string), do: normalize_and_slice(iban_string, 0..1)