ibandit 0.6.4 → 0.6.5

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: 70681e650c635f6195db9716fc93ad3ddc4d6587
4
- data.tar.gz: 8e3a5e7e949b8c55ab06e566a20aa509b73e8175
3
+ metadata.gz: 823a2e3a40462ece9f02dca4e2442017d1372b57
4
+ data.tar.gz: 153d927db1dc73912738f0f49396a97fb8e17024
5
5
  SHA512:
6
- metadata.gz: 270c923322faa85318a8b58fa0d4cc3dc68e00111d116918b4fbc54c9fc305175873d062955bf9630c025355c812ffb34f8a542ba72eaac40b806a8061de4e2d
7
- data.tar.gz: ef757fd03c27b661e0e98a9f84f3b2c871fb20ac0166d686f9d25fb55e047a354481056f423a49cd2a882769d4a7edcd9ff288870a76a5efdc0063e0d25b3274
6
+ metadata.gz: 14cc8a274cd0b5d41249a4d3d043a582aba730b096438d206de9aa008f88672f8f451e0ba196b1780443b13cb592af93b3706c3125ee05e6531989ff80c20239
7
+ data.tar.gz: 7c060ed0b1a379d0617210c8ab0e485a5c1f4ee32e66c706a27fbdd774c9c9926a8311f5ebac4aa3fb7d1d9005ce3ba9399a9b3baa4dd8c9a0a8734405a04e5a
@@ -1,3 +1,10 @@
1
+ ## Unreleased
2
+
3
+ ## 0.6.5 - July 30, 2015
4
+ - Add Romania to LocalDetailsCleaner and IBANAssembler
5
+ - Add Bulgaria to LocalDetailsCleaner and IBANAssembler
6
+ - Add Hungary to LocalDetailsCleaner and IBANAssembler
7
+
1
8
  ## 0.6.4 - July 28, 2015
2
9
 
3
10
  - Add Poland to LocalDetailsCleaner and IBANAssembler
data/README.md CHANGED
@@ -174,6 +174,15 @@ iban = Ibandit::IBAN.new(
174
174
  )
175
175
  iban.iban # => "BE62510007547061"
176
176
 
177
+ # Bulgaria
178
+ iban = Ibandit::IBAN.new(
179
+ country_code: 'BG',
180
+ bank_code: 'BNBG',
181
+ branch_code: '9661'
182
+ account_number: '1020345678'
183
+ )
184
+ iban.iban # => "BG80BNBG96611020345678"
185
+
177
186
  # Cyprus
178
187
  iban = Ibandit::IBAN.new(
179
188
  country_code: 'CY',
@@ -240,6 +249,13 @@ iban = Ibandit::IBAN.new(
240
249
  )
241
250
  iban.iban # => "GR16011012500000000012300695"
242
251
 
252
+ # Hungary
253
+ iban = Ibandit::IBAN.new(
254
+ country_code: 'HU',
255
+ account_number: '11773016-11111018'
256
+ )
257
+ iban.iban # => "HU42117730161111101800000000"
258
+
243
259
  # Ireland
244
260
  iban = Ibandit::IBAN.new(
245
261
  country_code: 'IE',
@@ -339,6 +355,14 @@ iban = Ibandit::IBAN.new(
339
355
  )
340
356
  iban.iban # => "PT50000200230023843000578"
341
357
 
358
+ # Romania
359
+ iban = Ibandit::IBAN.new(
360
+ country_code: 'RO',
361
+ bank_code: 'AAAA',
362
+ account_number: '1B31007593840000'
363
+ )
364
+ iban.iban # => "RO49AAAA1B31007593840000"
365
+
342
366
  # San Marino
343
367
  iban = Ibandit::IBAN.new(
344
368
  country_code: 'SM',
@@ -84,6 +84,24 @@ 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 last digit
88
+ # of a Hungarian account number when given the initial digits.
89
+ def self.hungarian(string)
90
+ weights = [9, 7, 3, 1]
91
+
92
+ scaled_values = string.chars.map.with_index do |char, index|
93
+ unless char.to_i.to_s == char
94
+ raise InvalidCharacterError,
95
+ "Unexpected non-numeric character '#{char}'"
96
+ end
97
+
98
+ char.to_i * weights[index % weights.size]
99
+ end
100
+
101
+ result = 10 - scaled_values.inject(:+) % 10
102
+ result < 10 ? result.to_s : '0'
103
+ end
104
+
87
105
  # Currently unused in this gem. This method calculates the penultimate digit
88
106
  # of an Icelandic kennitala (included in the account number) when given the
89
107
  # first 8 digits.
@@ -1,7 +1,8 @@
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 IS IT LT LU
4
- LV MC MT NL NO PL PT SE SI SK SM).freeze
3
+ SUPPORTED_COUNTRY_CODES = %w(AT BE BG CY DE DK EE ES FI FR GB GR HU IE IS IT
4
+ LT LU LV MC MT NL NO PL PT RO SE SI SK
5
+ SM).freeze
5
6
 
6
7
  EXCEPTION_COUNTRY_CODES = %w(IT SM BE).freeze
7
8
 
@@ -84,7 +85,7 @@ module Ibandit
84
85
 
85
86
  def self.required_fields(country_code)
86
87
  case country_code
87
- when *%w(AT CY DE EE FI IS LT LU LV NL NO PL SE SI SK DK)
88
+ when *%w(AT CY DE DK EE FI IS LT LU LV NL NO PL RO SE SI SK)
88
89
  %i(bank_code account_number)
89
90
  when 'BE'
90
91
  %i(account_number)
@@ -1,7 +1,8 @@
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 IS IT LT LU
4
- LV MC MT NL NO PL PT SE SI SK SM).freeze
3
+ SUPPORTED_COUNTRY_CODES = %w(AT BE BG CY DE DK EE ES FI FR GB GR HU IE IS IT
4
+ LT LU LV MC MT NL NO PL PT RO SE SI SK
5
+ SM).freeze
5
6
 
6
7
  def self.clean(local_details)
7
8
  country_code = local_details[:country_code]
@@ -27,9 +28,9 @@ module Ibandit
27
28
 
28
29
  def self.required_fields(country_code)
29
30
  case country_code
30
- when 'AT', 'CY', 'DE', 'FI', 'LT', 'LU', 'LV', 'NL', 'SI', 'SK'
31
+ when 'AT', 'CY', 'DE', 'FI', 'LT', 'LU', 'LV', 'NL', 'RO', 'SI', 'SK'
31
32
  %i(bank_code account_number)
32
- when 'BE', 'DK', 'EE', 'ES', 'SE', 'NO', 'PL', 'IS'
33
+ when 'BE', 'DK', 'EE', 'ES', 'HU', 'IS', 'NO', 'PL', 'SE'
33
34
  %i(account_number)
34
35
  when 'GB', 'IE', 'MT'
35
36
  if Ibandit.bic_finder.nil? then %i(bank_code branch_code account_number)
@@ -63,6 +64,11 @@ module Ibandit
63
64
  }
64
65
  end
65
66
 
67
+ def self.clean_bg_details(local_details)
68
+ # Bulgarian national bank details were replaced with IBANs in 2006.
69
+ local_details
70
+ end
71
+
66
72
  def self.clean_cy_details(local_details)
67
73
  # Account number may be 7-16 digits long.
68
74
  # Add leading zeros to account number if < 16 digits.
@@ -227,6 +233,32 @@ module Ibandit
227
233
  local_details
228
234
  end
229
235
 
236
+ def self.clean_hu_details(local_details)
237
+ # This method supports being passed the component IBAN parts, as defined
238
+ # by SWIFT, or a single 16 or 24 digit string.
239
+ if local_details[:bank_code] || local_details[:branch_code]
240
+ return local_details
241
+ end
242
+
243
+ cleaned_acct_number = local_details[:account_number].gsub(/[-\s]/, '')
244
+
245
+ case cleaned_acct_number.length
246
+ when 16
247
+ {
248
+ bank_code: cleaned_acct_number.slice(0, 3),
249
+ branch_code: cleaned_acct_number.slice(3, 4),
250
+ account_number: cleaned_acct_number.slice(7, 9).ljust(17, '0')
251
+ }
252
+ when 24
253
+ {
254
+ bank_code: cleaned_acct_number.slice(0, 3),
255
+ branch_code: cleaned_acct_number.slice(3, 4),
256
+ account_number: cleaned_acct_number.slice(7, 17)
257
+ }
258
+ else local_details
259
+ end
260
+ end
261
+
230
262
  def self.clean_ie_details(local_details)
231
263
  # Ireland uses the same local details as the United Kingdom
232
264
  branch_code = local_details[:branch_code].gsub(/[-\s]/, '')
@@ -365,6 +397,11 @@ module Ibandit
365
397
  local_details
366
398
  end
367
399
 
400
+ def self.clean_ro_details(local_details)
401
+ # Romanian national bank details were replaced with IBANs in 2004.
402
+ local_details
403
+ end
404
+
368
405
  def self.clean_se_details(local_details)
369
406
  converted_details =
370
407
  SwedishDetailsConverter.convert(local_details[:account_number])
@@ -1,3 +1,3 @@
1
1
  module Ibandit
2
- VERSION = '0.6.4'.freeze
2
+ VERSION = '0.6.5'.freeze
3
3
  end
@@ -104,6 +104,28 @@ describe Ibandit::CheckDigit do
104
104
  end
105
105
  end
106
106
 
107
+ describe '.hungarian' do
108
+ subject { described_class.hungarian(account_number) }
109
+
110
+ let(:account_number) { '1234567' }
111
+ it { is_expected.to eq('6') }
112
+
113
+ context 'with another account number (double checking!)' do
114
+ let(:account_number) { '1111101' }
115
+ it { is_expected.to eq('8') }
116
+ end
117
+
118
+ context 'with all zeros' do
119
+ let(:account_number) { '0000000' }
120
+ it { is_expected.to eq('0') }
121
+ end
122
+
123
+ context 'with a non-numeric character' do
124
+ let(:account_number) { '1BAD2014' }
125
+ specify { expect { subject }.to raise_error(/non-numeric character/) }
126
+ end
127
+ end
128
+
107
129
  describe '.icelandic' do
108
130
  subject { described_class.icelandic(kennitala) }
109
131
 
@@ -68,6 +68,31 @@ describe Ibandit::IBANAssembler do
68
68
  end
69
69
  end
70
70
 
71
+ context 'with BG as the country_code' do
72
+ let(:args) do
73
+ {
74
+ country_code: 'BG',
75
+ account_number: '1020345678',
76
+ bank_code: 'BNBG',
77
+ branch_code: '9661'
78
+ }
79
+ end
80
+
81
+ it { is_expected.to eq('BG80BNBG96611020345678') }
82
+
83
+ it_behaves_like 'allows round trips', 'BG80 BNBG 9661 1020 3456 78'
84
+
85
+ context 'without an account_number' do
86
+ before { args.delete(:account_number) }
87
+ it { is_expected.to be_nil }
88
+ end
89
+
90
+ context 'without a bank_code' do
91
+ before { args.delete(:bank_code) }
92
+ it { is_expected.to be_nil }
93
+ end
94
+ end
95
+
71
96
  context 'with CY as the country_code' do
72
97
  let(:args) do
73
98
  {
@@ -314,6 +339,48 @@ describe Ibandit::IBANAssembler do
314
339
  end
315
340
  end
316
341
 
342
+ context 'with HU as the country_code' do
343
+ let(:args) do
344
+ {
345
+ country_code: 'HU',
346
+ bank_code: '117',
347
+ branch_code: '7301',
348
+ account_number: '61111101800000000'
349
+ }
350
+ end
351
+
352
+ it { is_expected.to eq('HU42117730161111101800000000') }
353
+
354
+ it_behaves_like 'allows round trips', 'HU42 1177 3016 1111 1018 0000 0000'
355
+
356
+ context 'without a bank_code or branch_code' do
357
+ before { args.delete(:bank_code) }
358
+ before { args.delete(:branch_code) }
359
+ before { args[:account_number] = '11773016-11111018-00000000' }
360
+
361
+ it { is_expected.to be_nil }
362
+ end
363
+
364
+ context 'without a bank_code' do
365
+ before { args.delete(:bank_code) }
366
+ before { args[:account_number] = '11773016-11111018-00000000' }
367
+
368
+ it { is_expected.to be_nil }
369
+ end
370
+
371
+ context 'without a branch_code' do
372
+ before { args.delete(:branch_code) }
373
+ before { args[:account_number] = '11773016-11111018-00000000' }
374
+
375
+ it { is_expected.to be_nil }
376
+ end
377
+
378
+ context 'without an account_number' do
379
+ before { args.delete(:account_number) }
380
+ it { is_expected.to be_nil }
381
+ end
382
+ end
383
+
317
384
  context 'with IE as the country_code' do
318
385
  let(:args) do
319
386
  { country_code: 'IE',
@@ -652,6 +719,30 @@ describe Ibandit::IBANAssembler do
652
719
  end
653
720
  end
654
721
 
722
+ context 'with RO as the country_code' do
723
+ let(:args) do
724
+ {
725
+ country_code: 'RO',
726
+ account_number: '1B31007593840000',
727
+ bank_code: 'AAAA'
728
+ }
729
+ end
730
+
731
+ it { is_expected.to eq('RO49AAAA1B31007593840000') }
732
+
733
+ it_behaves_like 'allows round trips', 'RO49 AAAA 1B31 0075 9384 0000'
734
+
735
+ context 'without an account_number' do
736
+ before { args.delete(:account_number) }
737
+ it { is_expected.to be_nil }
738
+ end
739
+
740
+ context 'without a bank_code' do
741
+ before { args.delete(:bank_code) }
742
+ it { is_expected.to be_nil }
743
+ end
744
+ end
745
+
655
746
  context 'with SE as the country_code' do
656
747
  let(:args) do
657
748
  {
@@ -87,6 +87,30 @@ describe Ibandit::LocalDetailsCleaner do
87
87
  end
88
88
  end
89
89
 
90
+ context 'Bulgaria' do
91
+ let(:country_code) { 'BG' }
92
+ let(:bank_code) { 'BNBG' }
93
+ let(:branch_code) { '9661' }
94
+ let(:account_number) { '1020345678' }
95
+
96
+ it { is_expected.to eq(local_details) }
97
+
98
+ context 'without an account number' do
99
+ let(:account_number) { nil }
100
+ it { is_expected.to eq(local_details) }
101
+ end
102
+
103
+ context 'without a branch code' do
104
+ let(:branch_code) { nil }
105
+ it { is_expected.to eq(local_details) }
106
+ end
107
+
108
+ context 'without a bank code' do
109
+ let(:bank_code) { nil }
110
+ it { is_expected.to eq(local_details) }
111
+ end
112
+ end
113
+
90
114
  context 'Cyprus' do
91
115
  let(:country_code) { 'CY' }
92
116
  let(:account_number) { '0000001200527600' }
@@ -398,6 +422,52 @@ describe Ibandit::LocalDetailsCleaner do
398
422
  end
399
423
  end
400
424
 
425
+ context 'Hungary' do
426
+ let(:country_code) { 'HU' }
427
+ let(:bank_code) { '117' }
428
+ let(:branch_code) { '7301' }
429
+ let(:account_number) { '61111101800000000' }
430
+
431
+ it { is_expected.to eq(local_details) }
432
+
433
+ context 'with bank and branch codes in the account number' do
434
+ let(:bank_code) { nil }
435
+ let(:branch_code) { nil }
436
+
437
+ context 'with a full account number' do
438
+ let(:account_number) { '11773016-11111018-00000000' }
439
+
440
+ its([:bank_code]) { is_expected.to eq('117') }
441
+ its([:branch_code]) { is_expected.to eq('7301') }
442
+ its([:account_number]) { is_expected.to eq('61111101800000000') }
443
+ end
444
+
445
+ context 'with a short account number' do
446
+ let(:account_number) { '11773016-11111018' }
447
+
448
+ its([:bank_code]) { is_expected.to eq('117') }
449
+ its([:branch_code]) { is_expected.to eq('7301') }
450
+ its([:account_number]) { is_expected.to eq('61111101800000000') }
451
+ end
452
+
453
+ context 'with an invalid length account number' do
454
+ let(:account_number) { '11773016-1111101' }
455
+ it { is_expected.to eq(local_details) }
456
+ end
457
+
458
+ context 'with a bank code, too' do
459
+ let(:account_number) { '11773016-11111018' }
460
+ let(:bank_code) { '117' }
461
+ it { is_expected.to eq(local_details) }
462
+ end
463
+ end
464
+
465
+ context 'without an account number' do
466
+ let(:account_number) { nil }
467
+ it { is_expected.to eq(local_details) }
468
+ end
469
+ end
470
+
401
471
  context 'Ireland' do
402
472
  let(:country_code) { 'IE' }
403
473
  let(:bank_code) { 'AIBK' }
@@ -795,6 +865,24 @@ describe Ibandit::LocalDetailsCleaner do
795
865
  end
796
866
  end
797
867
 
868
+ context 'Romania' do
869
+ let(:country_code) { 'RO' }
870
+ let(:bank_code) { 'AAAA' }
871
+ let(:account_number) { '1B31007593840000' }
872
+
873
+ it { is_expected.to eq(local_details) }
874
+
875
+ context 'without an account number' do
876
+ let(:account_number) { nil }
877
+ it { is_expected.to eq(local_details) }
878
+ end
879
+
880
+ context 'without a bank code' do
881
+ let(:bank_code) { nil }
882
+ it { is_expected.to eq(local_details) }
883
+ end
884
+ end
885
+
798
886
  context 'Sweden' do
799
887
  let(:country_code) { 'SE' }
800
888
  let(:bank_code) { '501' }
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.4
4
+ version: 0.6.5
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-28 00:00:00.000000000 Z
11
+ date: 2015-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec