apeiros / iso-iban

Deal with International Bank Account Numbers (IBAN).
BSD 2-Clause "Simplified" License
15 stars 7 forks source link

IT and SM generate not acting consistently. #8

Open sliiser opened 7 years ago

sliiser commented 7 years ago

I wrote a short script expecting .bank_code and .branch_code to return the same values I pass into .generate. It worked well for all cases except for 2 of them. IT and SM. They are the only 2 countries whose bank_code does not start at position 4.

See the following snippet.

ISO::IBAN.specifications.keys.reject do |country|
  spec = ISO::IBAN.specification(country)
  bank_code = ('1' * spec.bank_code_length).presence
  branch_code = ('2' * spec.branch_code_length).presence
  account_code = ('3' * spec.account_code_length).presence
  iban = ISO::IBAN.generate(country, *[bank_code, branch_code, account_code].compact)
  iban.bank_code == bank_code && iban.branch_code == branch_code && iban.account_code == account_code
end

The resulting array contains just 'IT' and 'SM'.

If the former behaviour is expected, then please tell me how is generate supposed to be used.

Using ruby 2.3.3p222 on mac os and iso-iban (0.1.3).

apeiros commented 7 years ago

Hi @sliiser If you look at https://github.com/apeiros/iso-iban/blob/master/dev/ErrorsInRegistry.markdown you can see that the official iban specs are riddled with errors. I suspect it's due to yet another bug in the specs. I'll investigate it. Thanks for reporting!