diff --git a/data/raw/pseudo_ibans.yml b/data/raw/pseudo_ibans.yml index e38f133..0cecd94 100644 --- a/data/raw/pseudo_ibans.yml +++ b/data/raw/pseudo_ibans.yml @@ -13,13 +13,16 @@ AU: :pseudo_iban_account_number_length: 10 :national_id_length: 6 CA: - :bank_code_length: 4 + :bank_code_length: !ruby/range + begin: 3 + end: 4 + excl: false :branch_code_length: 5 :account_number_length: !ruby/range begin: 7 end: 12 excl: false - :bank_code_format: "\\d{4}" + :bank_code_format: "\\d{3,4}" :branch_code_format: "0{0,4}[1-9][0-9]{0,4}" :account_number_format: "(?!0+\\z)\\d{7,12}" :national_id_length: 9 diff --git a/data/structures.yml b/data/structures.yml index 5878b57..57a34c0 100644 --- a/data/structures.yml +++ b/data/structures.yml @@ -1493,13 +1493,16 @@ AU: :pseudo_iban_account_number_length: 10 :national_id_length: 6 CA: - :bank_code_length: 4 + :bank_code_length: !ruby/range + begin: 3 + end: 4 + excl: false :branch_code_length: 5 :account_number_length: !ruby/range begin: 7 end: 12 excl: false - :bank_code_format: "\\d{4}" + :bank_code_format: "\\d{3,4}" :branch_code_format: 0{0,4}[1-9][0-9]{0,4} :account_number_format: "(?!0+\\z)\\d{7,12}" :national_id_length: 9 diff --git a/lib/ibandit/iban.rb b/lib/ibandit/iban.rb index ec1c8f4..d678bd2 100644 --- a/lib/ibandit/iban.rb +++ b/lib/ibandit/iban.rb @@ -158,14 +158,21 @@ def valid_length? def valid_bank_code_length? return unless valid_country_code? - return true if structure[:bank_code_length]&.zero? + return true if structure[:bank_code_length].is_a?(Integer) && structure[:bank_code_length].zero? if swift_bank_code.nil? || swift_bank_code.empty? @errors[:bank_code] = Ibandit.translate(:is_required) return false end - return true if swift_bank_code.length == structure[:bank_code_length] + case structure[:bank_code_length] + when Range + if structure[:bank_code_length].include?(swift_bank_code.length) + return true + end + else + return true if swift_bank_code.length == structure[:bank_code_length] + end @errors[:bank_code] = Ibandit.translate(:wrong_length, expected: structure[:bank_code_length]) @@ -240,7 +247,7 @@ def valid_format? def valid_bank_code_format? return unless valid_bank_code_length? - return true if structure[:bank_code_length]&.zero? + return true if structure[:bank_code_length].is_a?(Integer) && structure[:bank_code_length].zero? if swift_bank_code&.match?( entire_string_regex(structure[:bank_code_format]),