ibandit 1.1.0.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,7 +46,7 @@ module Ibandit
46
46
  end
47
47
  end
48
48
 
49
- (scaled_values.inject(:+) % 26 + 65).chr
49
+ (scaled_values.sum % 26 + 65).chr
50
50
  end
51
51
  end
52
52
  end
@@ -2,5 +2,6 @@
2
2
 
3
3
  module Ibandit
4
4
  class InvalidCharacterError < StandardError; end
5
+
5
6
  class UnsupportedAccountDetails < StandardError; end
6
7
  end
@@ -307,7 +307,7 @@ module Ibandit
307
307
  end
308
308
 
309
309
  def sum_of_weighted_values
310
- weighted_values.reduce(0, &:+)
310
+ weighted_values.sum
311
311
  end
312
312
 
313
313
  def weighted_values
@@ -550,7 +550,7 @@ module Ibandit
550
550
  end
551
551
 
552
552
  def sum_of_weighted_digits
553
- weighted_digits.reduce(0, &:+)
553
+ weighted_digits.sum
554
554
  end
555
555
 
556
556
  def weighted_digits
data/lib/ibandit/iban.rb CHANGED
@@ -9,7 +9,8 @@ module Ibandit
9
9
  :swift_account_number, :source
10
10
 
11
11
  def initialize(argument)
12
- if argument.is_a?(String)
12
+ case argument
13
+ when String
13
14
  input = argument.to_s.gsub(/\s+/, "").upcase
14
15
 
15
16
  pseudo_iban_splitter = PseudoIBANSplitter.new(input)
@@ -24,7 +25,7 @@ module Ibandit
24
25
  @iban = input
25
26
  extract_swift_details_from_iban!
26
27
  end
27
- elsif argument.is_a?(Hash)
28
+ when Hash
28
29
  @source = :local_details
29
30
  build_iban_from_local_details(argument)
30
31
  else
@@ -225,7 +226,7 @@ module Ibandit
225
226
  return unless valid_country_code?
226
227
  return unless structure[:bban_format]
227
228
 
228
- if bban&.match?(Regexp.new(structure[:bban_format]))
229
+ if bban&.match?(entire_string_regex(structure[:bban_format]))
229
230
  true
230
231
  else
231
232
  @errors[:format] = Ibandit.translate(:invalid_format,
@@ -238,7 +239,9 @@ module Ibandit
238
239
  return unless valid_bank_code_length?
239
240
  return true if structure[:bank_code_length]&.zero?
240
241
 
241
- if swift_bank_code&.match?(Regexp.new(structure[:bank_code_format]))
242
+ if swift_bank_code&.match?(
243
+ entire_string_regex(structure[:bank_code_format]),
244
+ )
242
245
  true
243
246
  else
244
247
  @errors[:bank_code] = Ibandit.translate(:is_invalid)
@@ -250,7 +253,9 @@ module Ibandit
250
253
  return unless valid_branch_code_length?
251
254
  return true unless structure[:branch_code_format]
252
255
 
253
- if swift_branch_code&.match?(Regexp.new(structure[:branch_code_format]))
256
+ if swift_branch_code&.match?(
257
+ entire_string_regex(structure[:branch_code_format]),
258
+ )
254
259
  true
255
260
  else
256
261
  @errors[:branch_code] = Ibandit.translate(:is_invalid)
@@ -262,7 +267,7 @@ module Ibandit
262
267
  return unless valid_account_number_length?
263
268
 
264
269
  if swift_account_number&.match?(
265
- Regexp.new(structure[:account_number_format]),
270
+ entire_string_regex(structure[:account_number_format]),
266
271
  )
267
272
  true
268
273
  else
@@ -499,6 +504,10 @@ module Ibandit
499
504
  Ibandit.structures[country_code]
500
505
  end
501
506
 
507
+ def entire_string_regex(pattern)
508
+ Regexp.new("\\A#{pattern}\\z")
509
+ end
510
+
502
511
  def formatted
503
512
  iban.to_s.gsub(/(.{4})/, '\1 ').strip
504
513
  end
@@ -89,7 +89,9 @@ module Ibandit
89
89
  end
90
90
 
91
91
  def self.clean_ca_details(local_details)
92
- return {} if local_details[:account_number].length < 7 # minimum length
92
+ account_number = local_details[:account_number].tr("-", "")
93
+
94
+ return {} if account_number.length < 7 # minimum length
93
95
 
94
96
  bank_code = if local_details[:bank_code].length == 3
95
97
  local_details[:bank_code].rjust(4, "0")
@@ -98,7 +100,7 @@ module Ibandit
98
100
  end
99
101
 
100
102
  {
101
- account_number: local_details[:account_number].rjust(12, "0"),
103
+ account_number: account_number.rjust(12, "0"),
102
104
  bank_code: bank_code,
103
105
  }
104
106
  end
@@ -512,7 +514,7 @@ module Ibandit
512
514
  bank_code = local_details[:bank_code]
513
515
  account_number = local_details[:account_number]
514
516
  else
515
- cleaned_acct_number = local_details[:account_number].gsub(/[\s]/, "")
517
+ cleaned_acct_number = local_details[:account_number].gsub(/\s/, "")
516
518
 
517
519
  bank_code = cleaned_acct_number.slice(2, 8)
518
520
  account_number = cleaned_acct_number[10..-1]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ibandit
4
- VERSION = "1.1.0.1"
4
+ VERSION = "1.3.0"
5
5
  end
@@ -134,7 +134,7 @@
134
134
  {
135
135
  "convertor": "001400",
136
136
  "valid": [
137
- { "bank_code": "10090603", "account_number": "60624", "converted_bank_code": "30060601" }
137
+ { "bank_code": "30060601", "account_number": "60624", "converted_bank_code": "30060601" }
138
138
  ]
139
139
  },
140
140
  {
@@ -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
@@ -112,6 +112,22 @@ describe Ibandit::IBAN do
112
112
  its(:local_check_digits) { is_expected.to be_nil }
113
113
  end
114
114
 
115
+ context "when the IBAN was created from a Belgian IBAN" do
116
+ let(:iban_code) { "BE62510007547061" }
117
+
118
+ its(:country_code) { is_expected.to eq("BE") }
119
+ its(:bank_code) { is_expected.to eq("510") }
120
+ its(:branch_code) { is_expected.to be_nil }
121
+ its(:account_number) { is_expected.to eq("510007547061") }
122
+ its(:account_number_suffix) { is_expected.to be_nil }
123
+ its(:swift_bank_code) { is_expected.to eq("510") }
124
+ its(:swift_branch_code) { is_expected.to be_nil }
125
+ its(:swift_account_number) { is_expected.to eq("510007547061") }
126
+ its(:swift_national_id) { is_expected.to eq("510") }
127
+ its(:local_check_digits) { is_expected.to eq("61") }
128
+ its(:bban) { is_expected.to eq("510007547061") }
129
+ end
130
+
115
131
  context "when the IBAN was created with local details" do
116
132
  let(:arg) do
117
133
  {
@@ -452,6 +468,13 @@ describe Ibandit::IBAN do
452
468
  its(:to_s) { is_expected.to eq("") }
453
469
  end
454
470
 
471
+ context "and account number has invalid characters in" do
472
+ let(:account_number) { "123456XX789" }
473
+ let(:bank_code) { "0036" }
474
+
475
+ its(:valid?) { is_expected.to be false }
476
+ end
477
+
455
478
  context "and a 12 digit account number" do
456
479
  let(:account_number) { "012345678900" }
457
480
  let(:bank_code) { "0036" }
@@ -2247,16 +2270,16 @@ describe Ibandit::IBAN do
2247
2270
 
2248
2271
  context "with an invalid branch code" do
2249
2272
  let(:iban_code) { "GB60BARC20000055779911" }
2273
+ let(:valid_bank_code) { true }
2274
+ let(:valid_branch_code) { false }
2275
+ let(:valid_account_number) { true }
2276
+
2250
2277
  before { Ibandit.bic_finder = double(call: "BARCGB22XXX") }
2251
2278
 
2252
2279
  after { Ibandit.bic_finder = nil }
2253
2280
 
2254
2281
  before { iban.valid_local_modulus_check? }
2255
2282
 
2256
- let(:valid_bank_code) { true }
2257
- let(:valid_branch_code) { false }
2258
- let(:valid_account_number) { true }
2259
-
2260
2283
  it "calls valid_branch_code? with an IBAN object" do
2261
2284
  expect(Ibandit.modulus_checker).
2262
2285
  to receive(:valid_branch_code?).
@@ -3109,7 +3132,7 @@ describe Ibandit::IBAN do
3109
3132
  end
3110
3133
 
3111
3134
  context "for a valid Belgian IBAN" do
3112
- let(:iban_code) { "BE62 5100 0754 7061" }
3135
+ let(:iban_code) { "BE68 5390 0754 7034" }
3113
3136
 
3114
3137
  it { is_expected.to be_valid }
3115
3138
  end
@@ -3156,6 +3179,18 @@ describe Ibandit::IBAN do
3156
3179
  it { is_expected.to_not be_valid }
3157
3180
  end
3158
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
+
3159
3194
  context "for a valid Cypriot IBAN" do
3160
3195
  let(:iban_code) { "CY17 0020 0128 0000 0012 0052 7600" }
3161
3196
 
@@ -3192,6 +3227,18 @@ describe Ibandit::IBAN do
3192
3227
  it { is_expected.to_not be_valid }
3193
3228
  end
3194
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
+
3195
3242
  context "for a valid Estonian IBAN" do
3196
3243
  let(:iban_code) { "EE38 2200 2210 2014 5685" }
3197
3244
 
@@ -3576,6 +3623,18 @@ describe Ibandit::IBAN do
3576
3623
  it { is_expected.to_not be_valid }
3577
3624
  end
3578
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
+
3579
3638
  context "for a valid Potuguese IBAN" do
3580
3639
  let(:iban_code) { "PT50 0002 0123 1234 5678 9015 4" }
3581
3640
 
@@ -3600,6 +3659,30 @@ describe Ibandit::IBAN do
3600
3659
  it { is_expected.to_not be_valid }
3601
3660
  end
3602
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
+
3603
3686
  context "for a valid Romanian IBAN" do
3604
3687
  let(:iban_code) { "RO49 AAAA 1B31 0075 9384 0000" }
3605
3688
 
@@ -3755,6 +3838,114 @@ describe Ibandit::IBAN do
3755
3838
 
3756
3839
  it { is_expected.to_not be_valid }
3757
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
3758
3949
  end
3759
3950
 
3760
3951
  describe "#local_check_digits" do
@@ -167,6 +167,12 @@ describe Ibandit::LocalDetailsCleaner do
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") }
170
+
171
+ context "with a hyphen" do
172
+ let(:account_number) { "0123456-789" }
173
+
174
+ its([:account_number]) { is_expected.to eq("000123456789") }
175
+ end
170
176
  end
171
177
 
172
178
  context "Cyprus" do
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.1.0.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GoCardless
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-17 00:00:00.000000000 Z
11
+ date: 2021-02-18 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.12.0
19
+ version: 2.24.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.12.0
26
+ version: 2.24.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -149,10 +149,12 @@ files:
149
149
  - ".gitignore"
150
150
  - ".rubocop.yml"
151
151
  - ".rubocop_todo.yml"
152
+ - ".ruby-version"
152
153
  - CHANGELOG.md
153
154
  - Gemfile
154
155
  - LICENSE
155
156
  - README.md
157
+ - Rakefile
156
158
  - TODO.md
157
159
  - bin/build_german_iban_rules.rb
158
160
  - bin/build_structure_file.rb
@@ -208,7 +210,7 @@ homepage: https://github.com/gocardless/ibandit
208
210
  licenses:
209
211
  - MIT
210
212
  metadata: {}
211
- post_install_message:
213
+ post_install_message:
212
214
  rdoc_options: []
213
215
  require_paths:
214
216
  - lib
@@ -223,8 +225,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
225
  - !ruby/object:Gem::Version
224
226
  version: '0'
225
227
  requirements: []
226
- rubygems_version: 3.0.3
227
- signing_key:
228
+ rubygems_version: 3.2.3
229
+ signing_key:
228
230
  specification_version: 4
229
231
  summary: Convert national banking details into IBANs, and vice-versa.
230
232
  test_files: []