From 9df44df29bac225361ffe214b8dcbc62e4a1e3ce Mon Sep 17 00:00:00 2001 From: Joseph Southan Date: Mon, 8 Mar 2021 18:50:17 +0000 Subject: [PATCH 1/2] Fix US and CA account numbers --- .rubocop.yml | 4 +-- README.md | 2 +- data/structures.yml | 10 ++++++-- ibandit.gemspec | 4 +-- lib/ibandit/iban.rb | 13 ++++++---- lib/ibandit/local_details_cleaner.rb | 10 +++----- spec/ibandit/iban_spec.rb | 30 +++++++++++----------- spec/ibandit/local_details_cleaner_spec.rb | 6 ++--- 8 files changed, 43 insertions(+), 36 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index a748ce6..256d36e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,9 +5,9 @@ inherit_gem: AllCops: TargetRubyVersion: 2.4 -# Limit lines to 80 characters. +# Limit lines to 90 characters. Layout/LineLength: - Max: 80 + Max: 90 Metrics/ClassLength: Max: 400 diff --git a/README.md b/README.md index e5f68fd..416f5d9 100644 --- a/README.md +++ b/README.md @@ -575,7 +575,7 @@ iban.iban # => nil iban = Ibandit::IBAN.new('USZZ026073150_______2715500356') iban.country_code # => "US" iban.bank_code # => "026073150" -iban.account_number # => "_______2715500356" +iban.account_number # => "2715500356" iban.iban # => nil ``` diff --git a/data/structures.yml b/data/structures.yml index ee89e41..07e5637 100644 --- a/data/structures.yml +++ b/data/structures.yml @@ -993,7 +993,10 @@ AU: CA: :bank_code_length: 4 :branch_code_length: 5 - :account_number_length: 12 + :account_number_length: !ruby/range + begin: 7 + end: 12 + excl: false :bank_code_format: "\\d{4}" :branch_code_format: "\\d{5}" :account_number_format: "\\d{7,12}" @@ -1015,7 +1018,10 @@ NZ: US: :bank_code_length: 9 :branch_code_length: 0 - :account_number_length: 17 + :account_number_length: !ruby/range + begin: 1 + end: 17 + excl: false :bank_code_format: "\\d{9}" :account_number_format: "_*\\d{1,17}" :national_id_length: 9 diff --git a/ibandit.gemspec b/ibandit.gemspec index 62c00c0..f13d35c 100644 --- a/ibandit.gemspec +++ b/ibandit.gemspec @@ -5,8 +5,8 @@ require File.expand_path("lib/ibandit/version", __dir__) Gem::Specification.new do |gem| gem.add_development_dependency "gc_ruboconfig", "~> 2.24.0" gem.add_development_dependency "nokogiri", "~> 1.6" - gem.add_development_dependency "pry", "~> 0.10" - gem.add_development_dependency "pry-nav", "~> 0.2" + gem.add_development_dependency "pry", "~> 0.13" + gem.add_development_dependency "pry-byebug", "~> 3.9" gem.add_development_dependency "rspec", "~> 3.3" gem.add_development_dependency "rspec-its", "~> 1.2" gem.add_development_dependency "rspec_junit_formatter", "~> 0.4.1" diff --git a/lib/ibandit/iban.rb b/lib/ibandit/iban.rb index 345bbbc..092afc8 100644 --- a/lib/ibandit/iban.rb +++ b/lib/ibandit/iban.rb @@ -174,9 +174,7 @@ def valid_bank_code_length? def valid_branch_code_length? return unless valid_country_code? - if swift_branch_code.to_s.length == structure[:branch_code_length] - return true - end + return true if swift_branch_code.to_s.length == structure[:branch_code_length] if structure[:branch_code_length]&.zero? @errors[:branch_code] = Ibandit.translate(:not_used_in_country, @@ -199,8 +197,13 @@ def valid_account_number_length? return false end - if swift_account_number.length == structure[:account_number_length] - return true + case structure[:account_number_length] + when Range + if structure[:account_number_length].include?(swift_account_number.length) + return true + end + else + return true if swift_account_number.length == structure[:account_number_length] end @errors[:account_number] = diff --git a/lib/ibandit/local_details_cleaner.rb b/lib/ibandit/local_details_cleaner.rb index 1937e5f..ffef196 100644 --- a/lib/ibandit/local_details_cleaner.rb +++ b/lib/ibandit/local_details_cleaner.rb @@ -91,7 +91,7 @@ def self.clean_be_details(local_details) def self.clean_ca_details(local_details) account_number = local_details[:account_number].tr("-", "") - return {} if account_number.length < 7 # minimum length + return {} unless (7..12).cover?(account_number.length) bank_code = if local_details[:bank_code].length == 3 local_details[:bank_code].rjust(4, "0") @@ -100,7 +100,7 @@ def self.clean_ca_details(local_details) end { - account_number: account_number.rjust(12, "0"), + account_number: account_number, bank_code: bank_code, } end @@ -113,7 +113,7 @@ def self.clean_us_details(local_details) { bank_code: local_details[:bank_code], - account_number: account_number.rjust(17, "_"), + account_number: account_number, } end @@ -330,9 +330,7 @@ def self.clean_hr_details(local_details) def self.clean_hu_details(local_details) # This method supports being passed the component IBAN parts, as defined # by SWIFT, or a single 16 or 24 digit string. - if local_details[:bank_code] || local_details[:branch_code] - return local_details - end + return local_details if local_details[:bank_code] || local_details[:branch_code] cleaned_acct_number = local_details[:account_number].gsub(/[-\s]/, "") diff --git a/spec/ibandit/iban_spec.rb b/spec/ibandit/iban_spec.rb index 82ff80e..ce0600a 100755 --- a/spec/ibandit/iban_spec.rb +++ b/spec/ibandit/iban_spec.rb @@ -418,12 +418,12 @@ its(:country_code) { is_expected.to eq("CA") } its(:bank_code) { is_expected.to eq("0036") } its(:branch_code) { is_expected.to eq("00063") } - its(:account_number) { is_expected.to eq("000000123456") } + its(:account_number) { is_expected.to eq("0123456") } its(:swift_bank_code) { is_expected.to eq("0036") } its(:swift_branch_code) { is_expected.to eq("00063") } - its(:swift_account_number) { is_expected.to eq("000000123456") } + its(:swift_account_number) { is_expected.to eq("0123456") } its(:swift_national_id) { is_expected.to eq("003600063") } - its(:pseudo_iban) { is_expected.to eq("CAZZ003600063000000123456") } + its(:pseudo_iban) { is_expected.to eq("CAZZ003600063_____0123456") } its(:iban) { is_expected.to be_nil } its(:valid?) { is_expected.to eq(true) } @@ -437,12 +437,12 @@ its(:country_code) { is_expected.to eq("CA") } its(:bank_code) { is_expected.to eq("36") } its(:branch_code) { is_expected.to eq("00063") } - its(:account_number) { is_expected.to eq("000000123456") } + its(:account_number) { is_expected.to eq("0123456") } its(:swift_bank_code) { is_expected.to eq("36") } its(:swift_branch_code) { is_expected.to eq("00063") } - its(:swift_account_number) { is_expected.to eq("000000123456") } + its(:swift_account_number) { is_expected.to eq("0123456") } its(:swift_national_id) { is_expected.to eq("3600063") } - its(:pseudo_iban) { is_expected.to eq("CAZZ__3600063000000123456") } + its(:pseudo_iban) { is_expected.to eq("CAZZ__3600063_____0123456") } its(:iban) { is_expected.to be_nil } its(:valid?) { is_expected.to eq(false) } @@ -456,12 +456,12 @@ its(:country_code) { is_expected.to eq("CA") } its(:bank_code) { is_expected.to eq("0036") } its(:branch_code) { is_expected.to eq("00063") } - its(:account_number) { is_expected.to eq("000000123456") } + its(:account_number) { is_expected.to eq("0123456") } its(:swift_bank_code) { is_expected.to eq("0036") } its(:swift_branch_code) { is_expected.to eq("00063") } - its(:swift_account_number) { is_expected.to eq("000000123456") } + its(:swift_account_number) { is_expected.to eq("0123456") } its(:swift_national_id) { is_expected.to eq("003600063") } - its(:pseudo_iban) { is_expected.to eq("CAZZ003600063000000123456") } + its(:pseudo_iban) { is_expected.to eq("CAZZ003600063_____0123456") } its(:iban) { is_expected.to be_nil } its(:valid?) { is_expected.to eq(true) } @@ -501,11 +501,11 @@ its(:country_code) { is_expected.to eq("CA") } its(:bank_code) { is_expected.to eq("0036") } its(:branch_code) { is_expected.to eq("00063") } - its(:account_number) { is_expected.to eq("000000123456") } + its(:account_number) { is_expected.to eq("0123456") } its(:swift_bank_code) { is_expected.to eq("0036") } its(:swift_branch_code) { is_expected.to eq("00063") } - its(:swift_account_number) { is_expected.to eq("000000123456") } - its(:pseudo_iban) { is_expected.to eq("CAZZ003600063000000123456") } + its(:swift_account_number) { is_expected.to eq("0123456") } + its(:pseudo_iban) { is_expected.to eq("CAZZ003600063_____0123456") } its(:iban) { is_expected.to be_nil } its(:valid?) { is_expected.to be true } @@ -518,7 +518,7 @@ it "is invalid and has the correct errors" do expect(subject.valid?).to eq(false) expect(subject.errors). - to eq(account_number: "is the wrong length (should be 12 characters)") + to eq(account_number: "is the wrong length (should be 7..12 characters)") end end @@ -709,10 +709,10 @@ its(:country_code) { is_expected.to eq("US") } its(:bank_code) { is_expected.to eq(bank_code) } - its(:account_number) { is_expected.to eq("__________0123456") } + its(:account_number) { is_expected.to eq("0123456") } its(:swift_bank_code) { is_expected.to eq(bank_code) } its(:swift_branch_code) { is_expected.to eq(nil) } - its(:swift_account_number) { is_expected.to eq("__________0123456") } + its(:swift_account_number) { is_expected.to eq("0123456") } its(:swift_national_id) { is_expected.to eq(bank_code) } its(:pseudo_iban) do diff --git a/spec/ibandit/local_details_cleaner_spec.rb b/spec/ibandit/local_details_cleaner_spec.rb index c86c804..0933f95 100644 --- a/spec/ibandit/local_details_cleaner_spec.rb +++ b/spec/ibandit/local_details_cleaner_spec.rb @@ -163,7 +163,7 @@ let(:bank_code) { "0036" } let(:branch_code) { "00063" } - its([:account_number]) { is_expected.to eq("000000123456") } + its([:account_number]) { is_expected.to eq("0123456") } its([:country_code]) { is_expected.to eq(country_code) } its([:bank_code]) { is_expected.to eq("0036") } its([:branch_code]) { is_expected.to eq("00063") } @@ -171,7 +171,7 @@ context "with a hyphen" do let(:account_number) { "0123456-789" } - its([:account_number]) { is_expected.to eq("000123456789") } + its([:account_number]) { is_expected.to eq("0123456789") } end end @@ -1311,7 +1311,7 @@ let(:account_number) { "0123456789" } its([:bank_code]) { is_expected.to eq(bank_code) } - its([:account_number]) { is_expected.to eq("_______0123456789") } + its([:account_number]) { is_expected.to eq("0123456789") } end end end From b093781b523d5cfe7ec6cf3489d837789dd82a7e Mon Sep 17 00:00:00 2001 From: Joseph Southan Date: Thu, 11 Mar 2021 16:56:39 +0000 Subject: [PATCH 2/2] Bump version 1.5.0 --- CHANGELOG.md | 5 ++++- lib/ibandit/version.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 371c21a..d482f47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,11 @@ +## 1.5.0 - March 11, 2021 + +- Fix issue with padding on Canadian and USA pseudo IBANs #198 + ## 1.4.1 - March 3, 2021 - Update BLZ data - BLZVZ FTSEX MD 652 - ## 1.4.0 - February 22, 2021 - [Breaking] Correct `swift_national_id` for Canadian Psudo Ibans. Before `swift_national_id` diff --git a/lib/ibandit/version.rb b/lib/ibandit/version.rb index 4b05866..1c8fffb 100644 --- a/lib/ibandit/version.rb +++ b/lib/ibandit/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Ibandit - VERSION = "1.4.1" + VERSION = "1.5.0" end