Skip to content

Commit

Permalink
[canada] - bank_code_length 4 -> 3
Browse files Browse the repository at this point in the history
  • Loading branch information
piiraa committed Aug 5, 2024
1 parent df14cd8 commit bb2bb05
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
7 changes: 5 additions & 2 deletions data/raw/pseudo_ibans.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions data/structures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions lib/ibandit/iban.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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]),
Expand Down

0 comments on commit bb2bb05

Please sign in to comment.