ibandit 1.13.0 → 1.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +9 -0
- data/bin/build_structure_file.rb +221 -114
- data/config/locales/da.yml +7 -0
- data/config/locales/de.yml +7 -0
- data/config/locales/en.yml +7 -0
- data/config/locales/es.yml +7 -0
- data/config/locales/fr.yml +7 -0
- data/config/locales/it.yml +9 -1
- data/config/locales/nb.yml +7 -0
- data/config/locales/nl.yml +7 -0
- data/config/locales/pt.yml +7 -0
- data/config/locales/sl.yml +7 -0
- data/config/locales/sv.yml +7 -0
- data/data/raw/IBANSTRUCTURE.xml +1134 -292
- data/data/raw/IBAN_Registry.txt +51 -48
- data/data/raw/pseudo_ibans.yml +52 -0
- data/data/raw/structure_additions.yml +29 -1
- data/data/structures.yml +524 -25
- data/lib/ibandit/constants.rb +5 -1
- data/lib/ibandit/iban.rb +13 -13
- data/lib/ibandit/iban_assembler.rb +1 -1
- data/lib/ibandit/local_details_cleaner.rb +7 -7
- data/lib/ibandit/sweden/local_details_converter.rb +1 -1
- data/lib/ibandit/version.rb +1 -1
- data/lib/ibandit.rb +1 -1
- data/spec/ibandit/iban_assembler_spec.rb +48 -0
- data/spec/ibandit/iban_spec.rb +375 -2212
- data/spec/spec_helper.rb +6 -44
- metadata +4 -3
data/lib/ibandit/constants.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Ibandit
|
4
4
|
module Constants
|
5
|
-
CONSTRUCTABLE_IBAN_COUNTRY_CODES = %w[AT BE BG CY CZ DE DK EE ES FI FR GB GR
|
5
|
+
CONSTRUCTABLE_IBAN_COUNTRY_CODES = %w[AT BE BG CY CZ DE DK EE ES FI FO FR GB GL GR
|
6
6
|
HR HU IE IS IT LT LU LV MC MT NL NO PL
|
7
7
|
PT RO SE SI SK SM].freeze
|
8
8
|
|
@@ -25,5 +25,9 @@ module Ibandit
|
|
25
25
|
DECONSTRUCTABLE_IBAN_COUNTRY_CODES +
|
26
26
|
PSEUDO_IBAN_COUNTRY_CODES
|
27
27
|
).uniq
|
28
|
+
|
29
|
+
SUPPORTED_LOCALES = %w[
|
30
|
+
da de en es fr it nb nl pt sl sv
|
31
|
+
].freeze
|
28
32
|
end
|
29
33
|
end
|
data/lib/ibandit/iban.rb
CHANGED
@@ -64,7 +64,7 @@ module Ibandit
|
|
64
64
|
def account_number_suffix
|
65
65
|
return nil unless country_code == "NZ"
|
66
66
|
|
67
|
-
@account_number[7
|
67
|
+
@account_number[7..]
|
68
68
|
end
|
69
69
|
|
70
70
|
def local_check_digits
|
@@ -77,7 +77,7 @@ module Ibandit
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def bban
|
80
|
-
iban[4
|
80
|
+
iban[4..] unless iban.nil?
|
81
81
|
end
|
82
82
|
|
83
83
|
def pseudo_iban
|
@@ -247,7 +247,7 @@ module Ibandit
|
|
247
247
|
)
|
248
248
|
true
|
249
249
|
else
|
250
|
-
@errors[:bank_code] = Ibandit.translate(:
|
250
|
+
@errors[:bank_code] = Ibandit.translate(:has_invalid_format)
|
251
251
|
false
|
252
252
|
end
|
253
253
|
end
|
@@ -261,7 +261,7 @@ module Ibandit
|
|
261
261
|
)
|
262
262
|
true
|
263
263
|
else
|
264
|
-
@errors[:branch_code] = Ibandit.translate(:
|
264
|
+
@errors[:branch_code] = Ibandit.translate(:has_invalid_format)
|
265
265
|
false
|
266
266
|
end
|
267
267
|
end
|
@@ -274,7 +274,7 @@ module Ibandit
|
|
274
274
|
)
|
275
275
|
true
|
276
276
|
else
|
277
|
-
@errors[:account_number] = Ibandit.translate(:
|
277
|
+
@errors[:account_number] = Ibandit.translate(:has_invalid_format)
|
278
278
|
false
|
279
279
|
end
|
280
280
|
end
|
@@ -332,7 +332,7 @@ module Ibandit
|
|
332
332
|
def valid_swedish_swift_details?
|
333
333
|
unless Sweden::Validator.bank_code_exists?(swift_bank_code)
|
334
334
|
bank_code_field = bank_code.nil? ? :account_number : :bank_code
|
335
|
-
@errors[bank_code_field] = Ibandit.translate(:
|
335
|
+
@errors[bank_code_field] = Ibandit.translate(:bank_code_does_not_exist)
|
336
336
|
@errors.delete(:bank_code) if bank_code.nil?
|
337
337
|
return false
|
338
338
|
end
|
@@ -344,7 +344,7 @@ module Ibandit
|
|
344
344
|
)
|
345
345
|
|
346
346
|
unless length_valid
|
347
|
-
@errors[:account_number] = Ibandit.translate(:
|
347
|
+
@errors[:account_number] = Ibandit.translate(:has_invalid_length)
|
348
348
|
return false
|
349
349
|
end
|
350
350
|
|
@@ -353,7 +353,7 @@ module Ibandit
|
|
353
353
|
|
354
354
|
def valid_swedish_local_details?
|
355
355
|
unless Sweden::Validator.valid_clearing_code_length?(branch_code)
|
356
|
-
@errors[:branch_code] = Ibandit.translate(:
|
356
|
+
@errors[:branch_code] = Ibandit.translate(:has_invalid_clearing_code_length)
|
357
357
|
return false
|
358
358
|
end
|
359
359
|
|
@@ -363,7 +363,7 @@ module Ibandit
|
|
363
363
|
)
|
364
364
|
|
365
365
|
unless valid_serial_number
|
366
|
-
@errors[:account_number] = Ibandit.translate(:
|
366
|
+
@errors[:account_number] = Ibandit.translate(:has_invalid_serial_number)
|
367
367
|
return false
|
368
368
|
end
|
369
369
|
|
@@ -410,7 +410,7 @@ module Ibandit
|
|
410
410
|
(1 * (code_digits[2] + code_digits[5] + code_digits[8]))
|
411
411
|
) % 10
|
412
412
|
|
413
|
-
@errors[:bank_code] = Ibandit.translate(:
|
413
|
+
@errors[:bank_code] = Ibandit.translate(:failed_checksum_test) unless mod.zero?
|
414
414
|
|
415
415
|
mod.zero?
|
416
416
|
end
|
@@ -518,21 +518,21 @@ module Ibandit
|
|
518
518
|
def valid_modulus_check_bank_code?
|
519
519
|
return true if Ibandit.modulus_checker.valid_bank_code?(self)
|
520
520
|
|
521
|
-
@errors[:bank_code] = Ibandit.translate(:
|
521
|
+
@errors[:bank_code] = Ibandit.translate(:failed_modulus_check)
|
522
522
|
false
|
523
523
|
end
|
524
524
|
|
525
525
|
def valid_modulus_check_branch_code?
|
526
526
|
return true if Ibandit.modulus_checker.valid_branch_code?(self)
|
527
527
|
|
528
|
-
@errors[:branch_code] = Ibandit.translate(:
|
528
|
+
@errors[:branch_code] = Ibandit.translate(:failed_modulus_check)
|
529
529
|
false
|
530
530
|
end
|
531
531
|
|
532
532
|
def valid_modulus_check_account_number?
|
533
533
|
return true if Ibandit.modulus_checker.valid_account_number?(self)
|
534
534
|
|
535
|
-
@errors[:account_number] = Ibandit.translate(:
|
535
|
+
@errors[:account_number] = Ibandit.translate(:failed_modulus_check)
|
536
536
|
false
|
537
537
|
end
|
538
538
|
|
@@ -89,7 +89,7 @@ module Ibandit
|
|
89
89
|
|
90
90
|
def self.required_fields(country_code)
|
91
91
|
case country_code
|
92
|
-
when "AT", "CY", "CZ", "DE", "DK", "EE", "FI", "HR", "IS", "LT", "LU",
|
92
|
+
when "AT", "CY", "CZ", "DE", "DK", "EE", "FO", "FI", "GL", "HR", "IS", "LT", "LU",
|
93
93
|
"LV", "NL", "NO", "PL", "RO", "SE", "SI", "SK"
|
94
94
|
%i[bank_code account_number]
|
95
95
|
when "BE"
|
@@ -132,7 +132,7 @@ module Ibandit
|
|
132
132
|
if local_details[:branch_code]
|
133
133
|
local_details[:branch_code]
|
134
134
|
elsif cleaned_bank_code.length > 3
|
135
|
-
cleaned_bank_code[3
|
135
|
+
cleaned_bank_code[3..]
|
136
136
|
end
|
137
137
|
account_number =
|
138
138
|
if local_details[:account_number].length >= 7
|
@@ -247,7 +247,7 @@ module Ibandit
|
|
247
247
|
|
248
248
|
bank_code = cleaned_account_number.slice(0, 4)
|
249
249
|
branch_code = cleaned_account_number.slice(4, 4)
|
250
|
-
account_number = cleaned_account_number[8
|
250
|
+
account_number = cleaned_account_number[8..]
|
251
251
|
end
|
252
252
|
|
253
253
|
{
|
@@ -265,7 +265,7 @@ module Ibandit
|
|
265
265
|
if %w[4 5 6].include?(local_details[:bank_code][0])
|
266
266
|
[
|
267
267
|
local_details[:account_number][0],
|
268
|
-
local_details[:account_number][1
|
268
|
+
local_details[:account_number][1..].rjust(7, "0"),
|
269
269
|
].join
|
270
270
|
else
|
271
271
|
local_details[:account_number].rjust(8, "0")
|
@@ -380,7 +380,7 @@ module Ibandit
|
|
380
380
|
bank_code, *parts = local_details[:account_number].split("-")
|
381
381
|
else
|
382
382
|
bank_code = local_details[:account_number].slice(0, 4)
|
383
|
-
parts = Array(local_details[:account_number][4
|
383
|
+
parts = Array(local_details[:account_number][4..])
|
384
384
|
end
|
385
385
|
|
386
386
|
{
|
@@ -457,7 +457,7 @@ module Ibandit
|
|
457
457
|
cleaned_acct_number = local_details[:account_number].gsub(/[-.\s]/, "")
|
458
458
|
|
459
459
|
bank_code = cleaned_acct_number.slice(0, 4)
|
460
|
-
account_number = cleaned_acct_number[4
|
460
|
+
account_number = cleaned_acct_number[4..]
|
461
461
|
end
|
462
462
|
|
463
463
|
{
|
@@ -483,7 +483,7 @@ module Ibandit
|
|
483
483
|
cleaned_account_number = local_details[:account_number].tr("-", "")
|
484
484
|
bank_code = cleaned_account_number.slice(0, 2)
|
485
485
|
branch_code = cleaned_account_number.slice(2, 4)
|
486
|
-
account_number = cleaned_account_number[6
|
486
|
+
account_number = cleaned_account_number[6..]
|
487
487
|
end
|
488
488
|
|
489
489
|
if account_number && account_number.length == 9
|
@@ -515,7 +515,7 @@ module Ibandit
|
|
515
515
|
cleaned_acct_number = local_details[:account_number].gsub(/\s/, "")
|
516
516
|
|
517
517
|
bank_code = cleaned_acct_number.slice(2, 8)
|
518
|
-
account_number = cleaned_acct_number[10
|
518
|
+
account_number = cleaned_acct_number[10..]
|
519
519
|
end
|
520
520
|
|
521
521
|
{
|
data/lib/ibandit/version.rb
CHANGED
data/lib/ibandit.rb
CHANGED
@@ -210,6 +210,54 @@ describe Ibandit::IBANAssembler do
|
|
210
210
|
end
|
211
211
|
end
|
212
212
|
|
213
|
+
context "with FO as the country_code" do
|
214
|
+
let(:args) do
|
215
|
+
{ country_code: "FO",
|
216
|
+
bank_code: "1199",
|
217
|
+
account_number: "0003179680" }
|
218
|
+
end
|
219
|
+
|
220
|
+
it { is_expected.to eq("FO9111990003179680") }
|
221
|
+
|
222
|
+
it_behaves_like "allows round trips", "FO91 1199 0003 1796 80"
|
223
|
+
|
224
|
+
context "without a bank_code" do
|
225
|
+
before { args.delete(:bank_code) }
|
226
|
+
|
227
|
+
it { is_expected.to be_nil }
|
228
|
+
end
|
229
|
+
|
230
|
+
context "without an account_number" do
|
231
|
+
before { args.delete(:account_number) }
|
232
|
+
|
233
|
+
it { is_expected.to be_nil }
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
context "with GL as the country_code" do
|
238
|
+
let(:args) do
|
239
|
+
{ country_code: "GL",
|
240
|
+
bank_code: "1199",
|
241
|
+
account_number: "0003179680" }
|
242
|
+
end
|
243
|
+
|
244
|
+
it { is_expected.to eq("GL9111990003179680") }
|
245
|
+
|
246
|
+
it_behaves_like "allows round trips", "GL91 1199 0003 1796 80"
|
247
|
+
|
248
|
+
context "without a bank_code" do
|
249
|
+
before { args.delete(:bank_code) }
|
250
|
+
|
251
|
+
it { is_expected.to be_nil }
|
252
|
+
end
|
253
|
+
|
254
|
+
context "without an account_number" do
|
255
|
+
before { args.delete(:account_number) }
|
256
|
+
|
257
|
+
it { is_expected.to be_nil }
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
213
261
|
context "with EE as the country_code" do
|
214
262
|
let(:args) do
|
215
263
|
{
|