ibandit 1.13.0 → 1.15.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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..-1]
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..-1] unless iban.nil?
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(:is_invalid)
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(:is_invalid)
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(:is_invalid)
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(:is_invalid)
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(:is_invalid)
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(:is_invalid)
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(:is_invalid)
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(:is_invalid) unless mod.zero?
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(:is_invalid)
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(:is_invalid)
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(:is_invalid)
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..-1]
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..-1]
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..-1].rjust(7, "0"),
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..-1])
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..-1]
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..-1]
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..-1]
518
+ account_number = cleaned_acct_number[10..]
519
519
  end
520
520
 
521
521
  {
@@ -73,7 +73,7 @@ module Ibandit
73
73
 
74
74
  def serial_number
75
75
  serial_number = if @branch_code.nil?
76
- cleaned_account_number[clearing_code_length..-1]
76
+ cleaned_account_number[clearing_code_length..]
77
77
  else
78
78
  cleaned_account_number
79
79
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ibandit
4
- VERSION = "1.13.0"
4
+ VERSION = "1.15.0"
5
5
  end
data/lib/ibandit.rb CHANGED
@@ -37,7 +37,7 @@ module Ibandit
37
37
  end
38
38
 
39
39
  def translate(key, options = {})
40
- I18n.translate(key, scope: [:ibandit], **options)
40
+ I18n.translate(key, scope: [:ibandit], **options.merge(raise: true))
41
41
  end
42
42
  end
43
43
  end
@@ -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
  {