ibandit 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e6050324d2f310c77a0a54383362e1dd827ed94
4
- data.tar.gz: b59ac5d70f28fdda7e1b38d1308e976b4e229435
3
+ metadata.gz: 70681e650c635f6195db9716fc93ad3ddc4d6587
4
+ data.tar.gz: 8e3a5e7e949b8c55ab06e566a20aa509b73e8175
5
5
  SHA512:
6
- metadata.gz: 5fd009bce7b5802bd35d188948736f64668fe1aa28e1bc553fd221b9a8cf49d26ea9a69fb9be0cc2bf1dcfc0fb1de5fd692280527c69c8e381feefb32647f2ee
7
- data.tar.gz: e74d733a37d3178b0600bfe64697bd77c29c0eab197aeb0886b100cdd6afe1325bbeb407cecce383cdae4acbdd205238956b19e4ffa7e6aac0d3d21d83c714b9
6
+ metadata.gz: 270c923322faa85318a8b58fa0d4cc3dc68e00111d116918b4fbc54c9fc305175873d062955bf9630c025355c812ffb34f8a542ba72eaac40b806a8061de4e2d
7
+ data.tar.gz: ef757fd03c27b661e0e98a9f84f3b2c871fb20ac0166d686f9d25fb55e047a354481056f423a49cd2a882769d4a7edcd9ff288870a76a5efdc0063e0d25b3274
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.6.4 - July 28, 2015
2
+
3
+ - Add Poland to LocalDetailsCleaner and IBANAssembler
4
+ - Add Iceland to LocalDetailsCleaner and IBANAssembler
5
+
1
6
  ## 0.6.3 - July 25, 2015
2
7
 
3
8
  - Strip out additional '-' characters from Danish account numbers
data/README.md CHANGED
@@ -249,6 +249,14 @@ iban = Ibandit::IBAN.new(
249
249
  )
250
250
  iban.iban # => "IE29AIBK93115212345678"
251
251
 
252
+ # Iceland
253
+ iban = Ibandit::IBAN.new(
254
+ country_code: 'IS',
255
+ bank_code: '1175'
256
+ account_number: '26-19530-670269-6399'
257
+ )
258
+ iban.iban # => "IS501175260195306702696399"
259
+
252
260
  # Italy
253
261
  iban = Ibandit::IBAN.new(
254
262
  country_code: 'IT',
@@ -315,6 +323,13 @@ iban = Ibandit::IBAN.new(
315
323
  )
316
324
  iban.iban # => "NO9386011117947"
317
325
 
326
+ # Poland
327
+ iban = Ibandit::IBAN.new(
328
+ country_code: 'PL',
329
+ account_number: '60102010260000042270201111',
330
+ )
331
+ iban.iban # => "PL60102010260000042270201111"
332
+
318
333
  # Portugal
319
334
  iban = Ibandit::IBAN.new(
320
335
  country_code: 'PT',
@@ -40,6 +40,9 @@ GB:
40
40
  HU:
41
41
  :bban_format: \d{3}\d{4}\d{1}\d{15}\d{1}
42
42
  :account_number_format: \d{1}\d{15}\d{1}
43
+ IS:
44
+ :local_check_digit_position: 25
45
+ :local_check_digit_length: 1
43
46
  IT:
44
47
  :local_check_digit_position: 5
45
48
  :local_check_digit_length: 1
data/data/structures.yml CHANGED
@@ -418,6 +418,8 @@ IS:
418
418
  :bban_format: \d{4}\d{2}\d{6}\d{10}
419
419
  :bank_code_format: \d{4}
420
420
  :account_number_format: \d{2}\d{6}\d{10}
421
+ :local_check_digit_position: 25
422
+ :local_check_digit_length: 1
421
423
  IT:
422
424
  :bank_code_position: 6
423
425
  :bank_code_length: 5
@@ -84,6 +84,25 @@ module Ibandit
84
84
  (scaled_values.inject(:+) % 10).to_s
85
85
  end
86
86
 
87
+ # Currently unused in this gem. This method calculates the penultimate digit
88
+ # of an Icelandic kennitala (included in the account number) when given the
89
+ # first 8 digits.
90
+ def self.icelandic(string)
91
+ weights = [3, 2, 7, 6, 5, 4, 3, 2]
92
+
93
+ scaled_values = string.chars.map.with_index do |char, index|
94
+ unless char.to_i.to_s == char
95
+ raise InvalidCharacterError,
96
+ "Unexpected non-numeric character '#{char}'"
97
+ end
98
+
99
+ char.to_i * weights[index % weights.size]
100
+ end
101
+
102
+ result = 11 - scaled_values.inject(:+) % 11
103
+ result < 10 ? result.to_s : '0'
104
+ end
105
+
87
106
  # Currently unused in this gem. This method calculates the last digit
88
107
  # of a Slovakian account number (basic) when given the initial digits.
89
108
  def self.slovakian_prefix(string)
@@ -1,7 +1,7 @@
1
1
  module Ibandit
2
2
  module IBANAssembler
3
- SUPPORTED_COUNTRY_CODES = %w(AT BE CY DE DK EE ES FI FR GB GR IE IT LT LU LV
4
- MC MT NL NO PT SE SI SK SM).freeze
3
+ SUPPORTED_COUNTRY_CODES = %w(AT BE CY DE DK EE ES FI FR GB GR IE IS IT LT LU
4
+ LV MC MT NL NO PL PT SE SI SK SM).freeze
5
5
 
6
6
  EXCEPTION_COUNTRY_CODES = %w(IT SM BE).freeze
7
7
 
@@ -84,7 +84,7 @@ module Ibandit
84
84
 
85
85
  def self.required_fields(country_code)
86
86
  case country_code
87
- when *%w(AT CY DE EE FI LT LU LV NL NO SE SI SK DK)
87
+ when *%w(AT CY DE EE FI IS LT LU LV NL NO PL SE SI SK DK)
88
88
  %i(bank_code account_number)
89
89
  when 'BE'
90
90
  %i(account_number)
@@ -1,7 +1,7 @@
1
1
  module Ibandit
2
2
  module LocalDetailsCleaner
3
- SUPPORTED_COUNTRY_CODES = %w(AT BE CY DE DK EE ES FI FR GB GR IE IT LT LU LV
4
- MC MT NL NO PT SE SI SK SM).freeze
3
+ SUPPORTED_COUNTRY_CODES = %w(AT BE CY DE DK EE ES FI FR GB GR IE IS IT LT LU
4
+ LV MC MT NL NO PL PT SE SI SK SM).freeze
5
5
 
6
6
  def self.clean(local_details)
7
7
  country_code = local_details[:country_code]
@@ -29,7 +29,7 @@ module Ibandit
29
29
  case country_code
30
30
  when 'AT', 'CY', 'DE', 'FI', 'LT', 'LU', 'LV', 'NL', 'SI', 'SK'
31
31
  %i(bank_code account_number)
32
- when 'BE', 'EE', 'ES', 'SE', 'NO', 'DK'
32
+ when 'BE', 'DK', 'EE', 'ES', 'SE', 'NO', 'PL', 'IS'
33
33
  %i(account_number)
34
34
  when 'GB', 'IE', 'MT'
35
35
  if Ibandit.bic_finder.nil? then %i(bank_code branch_code account_number)
@@ -248,6 +248,23 @@ module Ibandit
248
248
  }
249
249
  end
250
250
 
251
+ def self.clean_is_details(local_details)
252
+ if local_details[:bank_code]
253
+ bank_code = local_details[:bank_code]
254
+ parts = local_details[:account_number].split('-')
255
+ elsif local_details[:account_number].include?('-')
256
+ bank_code, *parts = local_details[:account_number].split('-')
257
+ else
258
+ bank_code = local_details[:account_number].slice(0, 4)
259
+ parts = Array(local_details[:account_number][4..-1])
260
+ end
261
+
262
+ {
263
+ bank_code: bank_code.rjust(4, '0'),
264
+ account_number: pad_is_account_number(parts)
265
+ }
266
+ end
267
+
251
268
  def self.clean_it_details(local_details)
252
269
  # Add leading zeros to account number if < 12 digits.
253
270
  {
@@ -325,6 +342,25 @@ module Ibandit
325
342
  }
326
343
  end
327
344
 
345
+ def self.clean_pl_details(local_details)
346
+ # This method supports being passed the component IBAN parts, as defined
347
+ # by SWIFT, or a single 26 digit string.
348
+ if local_details[:bank_code]
349
+ bank_code = local_details[:bank_code]
350
+ account_number = local_details[:account_number]
351
+ else
352
+ cleaned_acct_number = local_details[:account_number].gsub(/[\s]/, '')
353
+
354
+ bank_code = cleaned_acct_number.slice(2, 8)
355
+ account_number = cleaned_acct_number[10..-1]
356
+ end
357
+
358
+ {
359
+ bank_code: bank_code,
360
+ account_number: account_number
361
+ }
362
+ end
363
+
328
364
  def self.clean_pt_details(local_details)
329
365
  local_details
330
366
  end
@@ -373,5 +409,17 @@ module Ibandit
373
409
  # San Marino uses the same local details method as France
374
410
  clean_it_details(local_details)
375
411
  end
412
+
413
+ def self.pad_is_account_number(parts)
414
+ hufo = parts[0].nil? ? '' : parts[0].rjust(2, '0')
415
+ reikningsnumer = parts[1].nil? ? '' : parts[1].rjust(6, '0')
416
+ ken_1 = parts[2].nil? ? '' : parts[2].rjust(6, '0')
417
+ ken_2 = parts[3].nil? ? '' : parts[3].rjust(4, '0')
418
+
419
+ kennitala = ken_1.empty? ? '' : (ken_1 + ken_2).rjust(10, '0')
420
+
421
+ hufo + reikningsnumer + kennitala
422
+ end
423
+ private_class_method :pad_is_account_number
376
424
  end
377
425
  end
@@ -1,3 +1,3 @@
1
1
  module Ibandit
2
- VERSION = '0.6.3'.freeze
2
+ VERSION = '0.6.4'.freeze
3
3
  end
@@ -104,6 +104,28 @@ describe Ibandit::CheckDigit do
104
104
  end
105
105
  end
106
106
 
107
+ describe '.icelandic' do
108
+ subject { described_class.icelandic(kennitala) }
109
+
110
+ let(:kennitala) { '52121206' }
111
+ it { is_expected.to eq('3') }
112
+
113
+ context 'with another kennitala (double checking!)' do
114
+ let(:kennitala) { '42027802' }
115
+ it { is_expected.to eq('0') }
116
+ end
117
+
118
+ context 'with a third kennitala (triple checking!)' do
119
+ let(:kennitala) { '12017433' }
120
+ it { is_expected.to eq('9') }
121
+ end
122
+
123
+ context 'with a non-numeric character' do
124
+ let(:kennitala) { '1BAD2014' }
125
+ specify { expect { subject }.to raise_error(/non-numeric character/) }
126
+ end
127
+ end
128
+
107
129
  describe '.norwegian' do
108
130
  subject { described_class.norwegian(account_number) }
109
131
 
@@ -342,6 +342,30 @@ describe Ibandit::IBANAssembler do
342
342
  end
343
343
  end
344
344
 
345
+ context 'with IS as the country_code' do
346
+ let(:args) do
347
+ {
348
+ country_code: 'IS',
349
+ account_number: '260195306702696399',
350
+ bank_code: '1175'
351
+ }
352
+ end
353
+
354
+ it { is_expected.to eq('IS501175260195306702696399') }
355
+
356
+ it_behaves_like 'allows round trips', 'IS50 1175 2601 9530 6702 6963 99'
357
+
358
+ context 'without an account_number' do
359
+ before { args.delete(:account_number) }
360
+ it { is_expected.to be_nil }
361
+ end
362
+
363
+ context 'without a bank_code' do
364
+ before { args.delete(:bank_code) }
365
+ it { is_expected.to be_nil }
366
+ end
367
+ end
368
+
345
369
  context 'with IT as the country_code' do
346
370
  let(:args) do
347
371
  {
@@ -572,6 +596,32 @@ describe Ibandit::IBANAssembler do
572
596
  end
573
597
  end
574
598
 
599
+ context 'with PL as the country_code' do
600
+ let(:args) do
601
+ {
602
+ country_code: 'PL',
603
+ bank_code: '10201026',
604
+ account_number: '0000042270201111'
605
+ }
606
+ end
607
+
608
+ it { is_expected.to eq('PL60102010260000042270201111') }
609
+
610
+ it_behaves_like 'allows round trips', 'PL60 1020 1026 0000 0422 7020 1111'
611
+
612
+ context 'without a bank_code' do
613
+ before { args.delete(:bank_code) }
614
+ before { args[:account_number] = '60102010260000042270201111' }
615
+
616
+ it { is_expected.to be_nil }
617
+ end
618
+
619
+ context 'without an account_number' do
620
+ before { args.delete(:account_number) }
621
+ it { is_expected.to be_nil }
622
+ end
623
+ end
624
+
575
625
  context 'with PT as the country_code' do
576
626
  let(:args) do
577
627
  {
@@ -1725,6 +1725,16 @@ describe Ibandit::IBAN do
1725
1725
  its(:local_check_digits) { is_expected.to eq('54') }
1726
1726
  end
1727
1727
 
1728
+ context 'with a Norwegian IBAN' do
1729
+ let(:iban_code) { 'NO9386011117947' }
1730
+ its(:local_check_digits) { is_expected.to eq('7') }
1731
+ end
1732
+
1733
+ context 'with an Icelandic IBAN' do
1734
+ let(:iban_code) { 'IS250311260024684606972049' }
1735
+ its(:local_check_digits) { is_expected.to eq('4') }
1736
+ end
1737
+
1728
1738
  context 'with a Slovakian IBAN' do
1729
1739
  let(:iban_code) { 'SK3112000000198742637541' }
1730
1740
  its(:local_check_digits) { is_expected.to eq('9') }
@@ -472,6 +472,52 @@ describe Ibandit::LocalDetailsCleaner do
472
472
  end
473
473
  end
474
474
 
475
+ context 'Iceland' do
476
+ let(:country_code) { 'IS' }
477
+ let(:bank_code) { '311' }
478
+ let(:account_number) { '26-2468-460697-2049' }
479
+
480
+ its([:bank_code]) { is_expected.to eq('0311') }
481
+ its([:account_number]) { is_expected.to eq('260024684606972049') }
482
+
483
+ context 'with bank code in the account number' do
484
+ let(:bank_code) { nil }
485
+ let(:account_number) { '311-26-2468-460697-2049' }
486
+
487
+ its([:bank_code]) { is_expected.to eq('0311') }
488
+ its([:account_number]) { is_expected.to eq('260024684606972049') }
489
+
490
+ context 'and no hyphens' do
491
+ let(:account_number) { '0311260024684606972049' }
492
+
493
+ its([:bank_code]) { is_expected.to eq('0311') }
494
+ its([:account_number]) { is_expected.to eq('260024684606972049') }
495
+ end
496
+ end
497
+
498
+ context 'with no hyphen in the kennitala' do
499
+ let(:account_number) { '26-2468-4606972049' }
500
+
501
+ its([:account_number]) { is_expected.to eq('260024684606972049') }
502
+ end
503
+
504
+ context 'with a short kennitala' do
505
+ let(:account_number) { '26-2468-60697-2049' }
506
+
507
+ its([:account_number]) { is_expected.to eq('260024680606972049') }
508
+
509
+ context 'without a hyphen' do
510
+ let(:account_number) { '26-2468-606972049' }
511
+ its([:account_number]) { is_expected.to eq('260024680606972049') }
512
+ end
513
+ end
514
+
515
+ context 'without an account number' do
516
+ let(:account_number) { nil }
517
+ it { is_expected.to eq(local_details) }
518
+ end
519
+ end
520
+
475
521
  context 'Italy' do
476
522
  let(:country_code) { 'IT' }
477
523
  let(:bank_code) { '05428' }
@@ -703,6 +749,28 @@ describe Ibandit::LocalDetailsCleaner do
703
749
  end
704
750
  end
705
751
 
752
+ context 'Poland' do
753
+ let(:country_code) { 'PL' }
754
+ let(:bank_code) { '10201026' }
755
+ let(:account_number) { '0000042270201111' }
756
+
757
+ it { is_expected.to eq(local_details) }
758
+
759
+ context 'with a full length account number' do
760
+ let(:bank_code) { nil }
761
+ let(:branch_code) { nil }
762
+ let(:account_number) { '60102010260000042270201111' }
763
+
764
+ its([:bank_code]) { is_expected.to eq('10201026') }
765
+ its([:account_number]) { is_expected.to eq('0000042270201111') }
766
+ end
767
+
768
+ context 'without an account number' do
769
+ let(:account_number) { nil }
770
+ it { is_expected.to eq(local_details) }
771
+ end
772
+ end
773
+
706
774
  context 'Portugal' do
707
775
  let(:country_code) { 'PT' }
708
776
  let(:bank_code) { '0002' }
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: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grey Baker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-25 00:00:00.000000000 Z
11
+ date: 2015-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec