From 5cfc3f5fa2d55909a70ac49180d5b8248006213b Mon Sep 17 00:00:00 2001 From: Danylo Negrienko Date: Wed, 15 May 2024 00:04:47 -0400 Subject: [PATCH] Check to existing country module before parsing bban --- lib/iban_ex/parser.ex | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/iban_ex/parser.ex b/lib/iban_ex/parser.ex index d90bcc0..fae5142 100644 --- a/lib/iban_ex/parser.ex +++ b/lib/iban_ex/parser.ex @@ -45,13 +45,23 @@ defmodule IbanEx.Parser do def parse_bban(bban_string, country_code, options \\ [incomplete: false]) def parse_bban(bban_string, country_code, incomplete: true) do - Country.country_module(country_code).incomplete_rule() - |> parse_bban_by_regex(bban_string) + case Country.is_country_code_supported?(country_code) do + true -> + Country.country_module(country_code).incomplete_rule() + |> parse_bban_by_regex(bban_string) + false -> + %{} + end end - def parse_bban(bban_string, country_code, _options) do - Country.country_module(country_code).rule() - |> parse_bban_by_regex(bban_string) + def parse_bban(bban_string, country_code, incomplete: false) do + case Country.is_country_code_supported?(country_code) do + true -> + Country.country_module(country_code).rule() + |> parse_bban_by_regex(bban_string) + false -> + %{} + end end defp parse_bban_by_regex(_regex, nil), do: %{}