ibandit 1.2.3 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -91,7 +91,7 @@ module Ibandit
91
91
  def self.clean_ca_details(local_details)
92
92
  account_number = local_details[:account_number].tr("-", "")
93
93
 
94
- return {} if account_number.length < 7 # minimum length
94
+ return {} unless (7..12).cover?(account_number.length)
95
95
 
96
96
  bank_code = if local_details[:bank_code].length == 3
97
97
  local_details[:bank_code].rjust(4, "0")
@@ -100,7 +100,7 @@ module Ibandit
100
100
  end
101
101
 
102
102
  {
103
- account_number: account_number.rjust(12, "0"),
103
+ account_number: account_number,
104
104
  bank_code: bank_code,
105
105
  }
106
106
  end
@@ -113,7 +113,7 @@ module Ibandit
113
113
 
114
114
  {
115
115
  bank_code: local_details[:bank_code],
116
- account_number: account_number.rjust(17, "_"),
116
+ account_number: account_number,
117
117
  }
118
118
  end
119
119
 
@@ -330,9 +330,7 @@ module Ibandit
330
330
  def self.clean_hu_details(local_details)
331
331
  # This method supports being passed the component IBAN parts, as defined
332
332
  # by SWIFT, or a single 16 or 24 digit string.
333
- if local_details[:bank_code] || local_details[:branch_code]
334
- return local_details
335
- end
333
+ return local_details if local_details[:bank_code] || local_details[:branch_code]
336
334
 
337
335
  cleaned_acct_number = local_details[:account_number].gsub(/[-\s]/, "")
338
336
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ibandit
4
- VERSION = "1.2.3"
4
+ VERSION = "1.6.0"
5
5
  end
@@ -11,7 +11,7 @@ describe Ibandit::IBANAssembler do
11
11
  account_number: iban.swift_account_number,
12
12
  branch_code: iban.swift_branch_code,
13
13
  bank_code: iban.swift_bank_code,
14
- }.reject { |_key, value| value.nil? }
14
+ }.compact
15
15
  end
16
16
 
17
17
  it "successfully reconstructs the IBAN" do
@@ -418,12 +418,12 @@ describe Ibandit::IBAN do
418
418
  its(:country_code) { is_expected.to eq("CA") }
419
419
  its(:bank_code) { is_expected.to eq("0036") }
420
420
  its(:branch_code) { is_expected.to eq("00063") }
421
- its(:account_number) { is_expected.to eq("000000123456") }
421
+ its(:account_number) { is_expected.to eq("0123456") }
422
422
  its(:swift_bank_code) { is_expected.to eq("0036") }
423
423
  its(:swift_branch_code) { is_expected.to eq("00063") }
424
- its(:swift_account_number) { is_expected.to eq("000000123456") }
425
- its(:swift_national_id) { is_expected.to eq("0036") }
426
- its(:pseudo_iban) { is_expected.to eq("CAZZ003600063000000123456") }
424
+ its(:swift_account_number) { is_expected.to eq("0123456") }
425
+ its(:swift_national_id) { is_expected.to eq("003600063") }
426
+ its(:pseudo_iban) { is_expected.to eq("CAZZ003600063_____0123456") }
427
427
 
428
428
  its(:iban) { is_expected.to be_nil }
429
429
  its(:valid?) { is_expected.to eq(true) }
@@ -437,12 +437,12 @@ describe Ibandit::IBAN do
437
437
  its(:country_code) { is_expected.to eq("CA") }
438
438
  its(:bank_code) { is_expected.to eq("36") }
439
439
  its(:branch_code) { is_expected.to eq("00063") }
440
- its(:account_number) { is_expected.to eq("000000123456") }
440
+ its(:account_number) { is_expected.to eq("0123456") }
441
441
  its(:swift_bank_code) { is_expected.to eq("36") }
442
442
  its(:swift_branch_code) { is_expected.to eq("00063") }
443
- its(:swift_account_number) { is_expected.to eq("000000123456") }
444
- its(:swift_national_id) { is_expected.to eq("3600") }
445
- its(:pseudo_iban) { is_expected.to eq("CAZZ__3600063000000123456") }
443
+ its(:swift_account_number) { is_expected.to eq("0123456") }
444
+ its(:swift_national_id) { is_expected.to eq("3600063") }
445
+ its(:pseudo_iban) { is_expected.to eq("CAZZ__3600063_____0123456") }
446
446
 
447
447
  its(:iban) { is_expected.to be_nil }
448
448
  its(:valid?) { is_expected.to eq(false) }
@@ -456,12 +456,12 @@ describe Ibandit::IBAN do
456
456
  its(:country_code) { is_expected.to eq("CA") }
457
457
  its(:bank_code) { is_expected.to eq("0036") }
458
458
  its(:branch_code) { is_expected.to eq("00063") }
459
- its(:account_number) { is_expected.to eq("000000123456") }
459
+ its(:account_number) { is_expected.to eq("0123456") }
460
460
  its(:swift_bank_code) { is_expected.to eq("0036") }
461
461
  its(:swift_branch_code) { is_expected.to eq("00063") }
462
- its(:swift_account_number) { is_expected.to eq("000000123456") }
463
- its(:swift_national_id) { is_expected.to eq("0036") }
464
- its(:pseudo_iban) { is_expected.to eq("CAZZ003600063000000123456") }
462
+ its(:swift_account_number) { is_expected.to eq("0123456") }
463
+ its(:swift_national_id) { is_expected.to eq("003600063") }
464
+ its(:pseudo_iban) { is_expected.to eq("CAZZ003600063_____0123456") }
465
465
 
466
466
  its(:iban) { is_expected.to be_nil }
467
467
  its(:valid?) { is_expected.to eq(true) }
@@ -486,7 +486,7 @@ describe Ibandit::IBAN do
486
486
  its(:swift_bank_code) { is_expected.to eq("0036") }
487
487
  its(:swift_branch_code) { is_expected.to eq("00063") }
488
488
  its(:swift_account_number) { is_expected.to eq("012345678900") }
489
- its(:swift_national_id) { is_expected.to eq("0036") }
489
+ its(:swift_national_id) { is_expected.to eq("003600063") }
490
490
  its(:pseudo_iban) { is_expected.to eq("CAZZ003600063012345678900") }
491
491
 
492
492
  its(:iban) { is_expected.to be_nil }
@@ -501,11 +501,11 @@ describe Ibandit::IBAN do
501
501
  its(:country_code) { is_expected.to eq("CA") }
502
502
  its(:bank_code) { is_expected.to eq("0036") }
503
503
  its(:branch_code) { is_expected.to eq("00063") }
504
- its(:account_number) { is_expected.to eq("000000123456") }
504
+ its(:account_number) { is_expected.to eq("0123456") }
505
505
  its(:swift_bank_code) { is_expected.to eq("0036") }
506
506
  its(:swift_branch_code) { is_expected.to eq("00063") }
507
- its(:swift_account_number) { is_expected.to eq("000000123456") }
508
- its(:pseudo_iban) { is_expected.to eq("CAZZ003600063000000123456") }
507
+ its(:swift_account_number) { is_expected.to eq("0123456") }
508
+ its(:pseudo_iban) { is_expected.to eq("CAZZ003600063_____0123456") }
509
509
 
510
510
  its(:iban) { is_expected.to be_nil }
511
511
  its(:valid?) { is_expected.to be true }
@@ -518,7 +518,7 @@ describe Ibandit::IBAN do
518
518
  it "is invalid and has the correct errors" do
519
519
  expect(subject.valid?).to eq(false)
520
520
  expect(subject.errors).
521
- to eq(account_number: "is the wrong length (should be 12 characters)")
521
+ to eq(account_number: "is the wrong length (should be 7..12 characters)")
522
522
  end
523
523
  end
524
524
 
@@ -709,10 +709,10 @@ describe Ibandit::IBAN do
709
709
 
710
710
  its(:country_code) { is_expected.to eq("US") }
711
711
  its(:bank_code) { is_expected.to eq(bank_code) }
712
- its(:account_number) { is_expected.to eq("__________0123456") }
712
+ its(:account_number) { is_expected.to eq("0123456") }
713
713
  its(:swift_bank_code) { is_expected.to eq(bank_code) }
714
714
  its(:swift_branch_code) { is_expected.to eq(nil) }
715
- its(:swift_account_number) { is_expected.to eq("__________0123456") }
715
+ its(:swift_account_number) { is_expected.to eq("0123456") }
716
716
  its(:swift_national_id) { is_expected.to eq(bank_code) }
717
717
 
718
718
  its(:pseudo_iban) do
@@ -3132,7 +3132,7 @@ describe Ibandit::IBAN do
3132
3132
  end
3133
3133
 
3134
3134
  context "for a valid Belgian IBAN" do
3135
- let(:iban_code) { "BE62 5100 0754 7061" }
3135
+ let(:iban_code) { "BE68 5390 0754 7034" }
3136
3136
 
3137
3137
  it { is_expected.to be_valid }
3138
3138
  end
@@ -3179,6 +3179,18 @@ describe Ibandit::IBAN do
3179
3179
  it { is_expected.to_not be_valid }
3180
3180
  end
3181
3181
 
3182
+ context "for a valid Costa Rican IBAN" do
3183
+ let(:iban_code) { "CR05 0152 0200 1026 2840 66" }
3184
+
3185
+ it { is_expected.to be_valid }
3186
+ end
3187
+
3188
+ context "for an invalid Costa Rican IBAN" do
3189
+ let(:iban_code) { "CR05 0152 0200 1026 2840" }
3190
+
3191
+ it { is_expected.to_not be_valid }
3192
+ end
3193
+
3182
3194
  context "for a valid Cypriot IBAN" do
3183
3195
  let(:iban_code) { "CY17 0020 0128 0000 0012 0052 7600" }
3184
3196
 
@@ -3215,6 +3227,18 @@ describe Ibandit::IBAN do
3215
3227
  it { is_expected.to_not be_valid }
3216
3228
  end
3217
3229
 
3230
+ context "for a valid Dominican Republic IBAN" do
3231
+ let(:iban_code) { "DO28 BAGR 0000 0001 2124 5361 1324" }
3232
+
3233
+ it { is_expected.to be_valid }
3234
+ end
3235
+
3236
+ context "for an invalid Dominican Republic IBAN" do
3237
+ let(:iban_code) { "DO28 BAGR 0000 0001 2124 5361" }
3238
+
3239
+ it { is_expected.to_not be_valid }
3240
+ end
3241
+
3218
3242
  context "for a valid Estonian IBAN" do
3219
3243
  let(:iban_code) { "EE38 2200 2210 2014 5685" }
3220
3244
 
@@ -3599,6 +3623,18 @@ describe Ibandit::IBAN do
3599
3623
  it { is_expected.to_not be_valid }
3600
3624
  end
3601
3625
 
3626
+ context "for a valid Palestinian IBAN" do
3627
+ let(:iban_code) { "PS92 PALS 0000 0000 0400 1234 5670 2" }
3628
+
3629
+ it { is_expected.to be_valid }
3630
+ end
3631
+
3632
+ context "for an invalid Palestinian IBAN" do
3633
+ let(:iban_code) { "PS92 PALS 0000 0000 0400 1234 5670" }
3634
+
3635
+ it { is_expected.to_not be_valid }
3636
+ end
3637
+
3602
3638
  context "for a valid Potuguese IBAN" do
3603
3639
  let(:iban_code) { "PT50 0002 0123 1234 5678 9015 4" }
3604
3640
 
@@ -3623,6 +3659,30 @@ describe Ibandit::IBAN do
3623
3659
  it { is_expected.to_not be_valid }
3624
3660
  end
3625
3661
 
3662
+ context "for a valid Kosovan IBAN" do
3663
+ let(:iban_code) { "XK05 1212 0123 4567 8906" }
3664
+
3665
+ it { is_expected.to be_valid }
3666
+ end
3667
+
3668
+ context "for an invalid Kosovan IBAN" do
3669
+ let(:iban_code) { "XK05 1212 0123 4567 890" }
3670
+
3671
+ it { is_expected.to_not be_valid }
3672
+ end
3673
+
3674
+ context "for a valid Timor-Leste IBAN" do
3675
+ let(:iban_code) { "TL38 0080 0123 4567 8910 157" }
3676
+
3677
+ it { is_expected.to be_valid }
3678
+ end
3679
+
3680
+ context "for an invalid Timor-Leste IBAN" do
3681
+ let(:iban_code) { "TL38 0080 0123 4567 8910" }
3682
+
3683
+ it { is_expected.to_not be_valid }
3684
+ end
3685
+
3626
3686
  context "for a valid Romanian IBAN" do
3627
3687
  let(:iban_code) { "RO49 AAAA 1B31 0075 9384 0000" }
3628
3688
 
@@ -3778,6 +3838,114 @@ describe Ibandit::IBAN do
3778
3838
 
3779
3839
  it { is_expected.to_not be_valid }
3780
3840
  end
3841
+
3842
+ context "with a valid LC iban" do
3843
+ let(:iban_code) { "LC55 HEMM 0001 0001 0012 0012 0002 3015" }
3844
+
3845
+ it { is_expected.to be_valid }
3846
+ end
3847
+
3848
+ context "with an invalid LC iban" do
3849
+ let(:iban_code) { "LC55 HEMM 0001 0001 0012 0012 0002" }
3850
+
3851
+ it { is_expected.to_not be_valid }
3852
+ end
3853
+
3854
+ context "with a valid UA iban" do
3855
+ let(:iban_code) { "UA21 3223 1300 0002 6007 2335 6600 1" }
3856
+
3857
+ it { is_expected.to be_valid }
3858
+ end
3859
+
3860
+ context "with an invalid UA iban" do
3861
+ let(:iban_code) { "UA21 3223 1300 0002 6007 2335 6600 " }
3862
+
3863
+ it { is_expected.to_not be_valid }
3864
+ end
3865
+
3866
+ context "with a valid ST iban" do
3867
+ let(:iban_code) { "ST23 0001 0001 0051 8453 1014 6" }
3868
+
3869
+ it { is_expected.to be_valid }
3870
+ end
3871
+
3872
+ context "with an invalid ST iban" do
3873
+ let(:iban_code) { "ST23 0001 0001 0051 8453 1014" }
3874
+
3875
+ it { is_expected.to_not be_valid }
3876
+ end
3877
+
3878
+ context "with a valid SC iban" do
3879
+ let(:iban_code) { "SC18 SSCB 1101 0000 0000 0000 1497 USD" }
3880
+
3881
+ it { is_expected.to be_valid }
3882
+ end
3883
+
3884
+ context "with an invalid SC iban" do
3885
+ let(:iban_code) { "SC18 SSCB 1101 0000 0000 0000 USD" }
3886
+
3887
+ it { is_expected.to_not be_valid }
3888
+ end
3889
+
3890
+ context "with a valid IQ iban" do
3891
+ let(:iban_code) { "IQ98 NBIQ 8501 2345 6789 012" }
3892
+
3893
+ it { is_expected.to be_valid }
3894
+ end
3895
+
3896
+ context "with an invalid IQ iban" do
3897
+ let(:iban_code) { "IQ98 NBIQ 8501 2345 6789" }
3898
+
3899
+ it { is_expected.to_not be_valid }
3900
+ end
3901
+
3902
+ context "with a valid SV iban" do
3903
+ let(:iban_code) { "SV 62 CENR 00000000000000700025" }
3904
+
3905
+ it { is_expected.to be_valid }
3906
+ end
3907
+
3908
+ context "with an invalid SV iban" do
3909
+ let(:iban_code) { "SV 62 CENR 00000000000000700" }
3910
+
3911
+ it { is_expected.to_not be_valid }
3912
+ end
3913
+
3914
+ context "with a valid BY iban" do
3915
+ let(:iban_code) { "BY13 NBRB 3600 9000 0000 2Z00 AB00" }
3916
+
3917
+ it { is_expected.to be_valid }
3918
+ end
3919
+
3920
+ context "with an invalid BY iban" do
3921
+ let(:iban_code) { "BY13 NBRB 3600 9000 0000 2Z00" }
3922
+
3923
+ it { is_expected.to_not be_valid }
3924
+ end
3925
+
3926
+ context "with a valid VA iban" do
3927
+ let(:iban_code) { "VA59 001 1230 0001 2345 678" }
3928
+
3929
+ it { is_expected.to be_valid }
3930
+ end
3931
+
3932
+ context "with an invalid VA iban" do
3933
+ let(:iban_code) { "VA59 001 1230 0001 2345" }
3934
+
3935
+ it { is_expected.to_not be_valid }
3936
+ end
3937
+
3938
+ context "with a valid EG iban" do
3939
+ let(:iban_code) { "EG380019000500000000263180002" }
3940
+
3941
+ it { is_expected.to be_valid }
3942
+ end
3943
+
3944
+ context "with an invalid EG iban" do
3945
+ let(:iban_code) { "EG3800190005000000002631800" }
3946
+
3947
+ it { is_expected.to_not be_valid }
3948
+ end
3781
3949
  end
3782
3950
 
3783
3951
  describe "#local_check_digits" do
@@ -163,7 +163,7 @@ describe Ibandit::LocalDetailsCleaner do
163
163
  let(:bank_code) { "0036" }
164
164
  let(:branch_code) { "00063" }
165
165
 
166
- its([:account_number]) { is_expected.to eq("000000123456") }
166
+ its([:account_number]) { is_expected.to eq("0123456") }
167
167
  its([:country_code]) { is_expected.to eq(country_code) }
168
168
  its([:bank_code]) { is_expected.to eq("0036") }
169
169
  its([:branch_code]) { is_expected.to eq("00063") }
@@ -171,7 +171,7 @@ describe Ibandit::LocalDetailsCleaner do
171
171
  context "with a hyphen" do
172
172
  let(:account_number) { "0123456-789" }
173
173
 
174
- its([:account_number]) { is_expected.to eq("000123456789") }
174
+ its([:account_number]) { is_expected.to eq("0123456789") }
175
175
  end
176
176
  end
177
177
 
@@ -1311,7 +1311,7 @@ describe Ibandit::LocalDetailsCleaner do
1311
1311
  let(:account_number) { "0123456789" }
1312
1312
 
1313
1313
  its([:bank_code]) { is_expected.to eq(bank_code) }
1314
- its([:account_number]) { is_expected.to eq("_______0123456789") }
1314
+ its([:account_number]) { is_expected.to eq("0123456789") }
1315
1315
  end
1316
1316
  end
1317
1317
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibandit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GoCardless
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-11 00:00:00.000000000 Z
11
+ date: 2021-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gc_ruboconfig
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.20.0
19
+ version: 2.25.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.20.0
26
+ version: 2.25.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,28 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.10'
47
+ version: '0.13'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.10'
54
+ version: '0.13'
55
55
  - !ruby/object:Gem::Dependency
56
- name: pry-nav
56
+ name: pry-byebug
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.2'
61
+ version: '3.9'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.2'
68
+ version: '3.9'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -146,9 +146,11 @@ extensions: []
146
146
  extra_rdoc_files: []
147
147
  files:
148
148
  - ".circleci/config.yml"
149
+ - ".github/dependabot.yml"
149
150
  - ".gitignore"
150
151
  - ".rubocop.yml"
151
152
  - ".rubocop_todo.yml"
153
+ - ".ruby-version"
152
154
  - CHANGELOG.md
153
155
  - Gemfile
154
156
  - LICENSE
@@ -224,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
226
  - !ruby/object:Gem::Version
225
227
  version: '0'
226
228
  requirements: []
227
- rubygems_version: 3.0.3
229
+ rubygems_version: 3.2.15
228
230
  signing_key:
229
231
  specification_version: 4
230
232
  summary: Convert national banking details into IBANs, and vice-versa.