ibandit 1.1.0.1 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -95,7 +95,7 @@ BE:
95
95
  :national_id_length: 3
96
96
  :bban_format: "\\d{3}\\d{7}\\d{2}"
97
97
  :bank_code_format: "\\d{3}"
98
- :account_number_format: "\\d{7}\\d{2}"
98
+ :account_number_format: "\\d{7}\\d{2}\\d{3}"
99
99
  :local_check_digit_position: 15
100
100
  :local_check_digit_length: 2
101
101
  BG:
@@ -902,7 +902,7 @@ US:
902
902
  :branch_code_length: 0
903
903
  :account_number_length: 17
904
904
  :bank_code_format: "\\d{9}"
905
- :account_number_format: "\\A_*\\d{1,17}\\z"
905
+ :account_number_format: "_*\\d{1,17}"
906
906
  :national_id_length: 9
907
907
  :pseudo_iban_bank_code_length: 9
908
908
  :pseudo_iban_branch_code_length: 0
@@ -3,7 +3,7 @@
3
3
  require File.expand_path("lib/ibandit/version", __dir__)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
- gem.add_development_dependency "gc_ruboconfig", "~> 2.12.0"
6
+ gem.add_development_dependency "gc_ruboconfig", "~> 2.17.0"
7
7
  gem.add_development_dependency "nokogiri", "~> 1.6"
8
8
  gem.add_development_dependency "pry", "~> 0.10"
9
9
  gem.add_development_dependency "pry-nav", "~> 0.2"
@@ -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.2.1"
5
5
  end
@@ -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?).
@@ -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.2.1
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: 2020-09-01 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.17.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.17.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -153,6 +153,7 @@ files:
153
153
  - Gemfile
154
154
  - LICENSE
155
155
  - README.md
156
+ - Rakefile
156
157
  - TODO.md
157
158
  - bin/build_german_iban_rules.rb
158
159
  - bin/build_structure_file.rb
@@ -208,7 +209,7 @@ homepage: https://github.com/gocardless/ibandit
208
209
  licenses:
209
210
  - MIT
210
211
  metadata: {}
211
- post_install_message:
212
+ post_install_message:
212
213
  rdoc_options: []
213
214
  require_paths:
214
215
  - lib
@@ -224,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
225
  version: '0'
225
226
  requirements: []
226
227
  rubygems_version: 3.0.3
227
- signing_key:
228
+ signing_key:
228
229
  specification_version: 4
229
230
  summary: Convert national banking details into IBANs, and vice-versa.
230
231
  test_files: []