bban parse function
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user