ibandit 0.6.5 → 0.6.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -1
- data/README.md +27 -20
- data/lib/ibandit/check_digit.rb +17 -0
- data/lib/ibandit/iban_assembler.rb +4 -4
- data/lib/ibandit/local_details_cleaner.rb +39 -20
- data/lib/ibandit/version.rb +1 -1
- data/spec/ibandit/check_digit_spec.rb +22 -0
- data/spec/ibandit/iban_assembler_spec.rb +46 -0
- data/spec/ibandit/local_details_cleaner_spec.rb +58 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f800e698be58f3378b478f197526c5d2bdec8770
|
4
|
+
data.tar.gz: f8650d0eca790ea52617ea1b46da45c5c7f47f3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07b6d6a4a99a90ebb8810b11aed7c8de97d8ce27c5c25a12902761650c49a88a2cd947f9e1fda776917a90d57cb20f55d9f871cd2d3977baf971bb831a9e9955
|
7
|
+
data.tar.gz: 0b895a47575ec3722376372b938218363d7bd996345932d4e6627242e5ca50b47680f7fd3cd425fca02769a59e42f7f08344660e8025d1b4068177e317576f35
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -183,6 +183,13 @@ iban = Ibandit::IBAN.new(
|
|
183
183
|
)
|
184
184
|
iban.iban # => "BG80BNBG96611020345678"
|
185
185
|
|
186
|
+
# Croatia
|
187
|
+
iban = Ibandit::IBAN.new(
|
188
|
+
country_code: 'HR',
|
189
|
+
account_number: '1001005-1863000160',
|
190
|
+
)
|
191
|
+
iban.iban # => "HR1210010051863000160"
|
192
|
+
|
186
193
|
# Cyprus
|
187
194
|
iban = Ibandit::IBAN.new(
|
188
195
|
country_code: 'CY',
|
@@ -192,13 +199,14 @@ iban = Ibandit::IBAN.new(
|
|
192
199
|
)
|
193
200
|
iban.iban # => "CY17002001280000001200527600"
|
194
201
|
|
195
|
-
#
|
202
|
+
# Czech Republic
|
196
203
|
iban = Ibandit::IBAN.new(
|
197
|
-
country_code: '
|
198
|
-
bank_code: '
|
199
|
-
|
204
|
+
country_code: 'CZ',
|
205
|
+
bank_code: '0800',
|
206
|
+
account_number_prefix: '19',
|
207
|
+
account_number: '2000145399'
|
200
208
|
)
|
201
|
-
iban.iban # => "
|
209
|
+
iban.iban # => "CZ6508000000192000145399"
|
202
210
|
|
203
211
|
# Denmark
|
204
212
|
iban = Ibandit::IBAN.new(
|
@@ -231,14 +239,13 @@ iban = Ibandit::IBAN.new(
|
|
231
239
|
)
|
232
240
|
iban.iban # => "FR1420041010050500013M02606"
|
233
241
|
|
234
|
-
#
|
242
|
+
# Germany
|
235
243
|
iban = Ibandit::IBAN.new(
|
236
|
-
country_code: '
|
237
|
-
bank_code: '
|
238
|
-
|
239
|
-
account_number: '55779911'
|
244
|
+
country_code: 'DE',
|
245
|
+
bank_code: '37040044',
|
246
|
+
account_number: '0532013000'
|
240
247
|
)
|
241
|
-
iban.iban # => "
|
248
|
+
iban.iban # => "DE89370400440532013000"
|
242
249
|
|
243
250
|
# Greece
|
244
251
|
iban = Ibandit::IBAN.new(
|
@@ -390,15 +397,6 @@ iban = Ibandit::IBAN.new(
|
|
390
397
|
iban.iban # => "SI56191000000123438"
|
391
398
|
|
392
399
|
# Spain
|
393
|
-
iban = Ibandit::IBAN.new(
|
394
|
-
country_code: 'ES',
|
395
|
-
bank_code: '2310',
|
396
|
-
branch_code: '0001',
|
397
|
-
account_number: '180000012345'
|
398
|
-
)
|
399
|
-
iban.iban # => "ES8023100001180000012345"
|
400
|
-
|
401
|
-
# Spain with 20 digit account number
|
402
400
|
iban = Ibandit::IBAN.new(
|
403
401
|
country_code: 'ES',
|
404
402
|
account_number: '23100001180000012345'
|
@@ -411,6 +409,15 @@ iban = Ibandit::IBAN.new(
|
|
411
409
|
account_number: '7507-1211203'
|
412
410
|
)
|
413
411
|
iban.iban # => "SE2680000000075071211203"
|
412
|
+
|
413
|
+
# United Kingdom
|
414
|
+
iban = Ibandit::IBAN.new(
|
415
|
+
country_code: 'GB',
|
416
|
+
bank_code: 'BARC', # optional if a BIC finder is configured
|
417
|
+
branch_code: '200000',
|
418
|
+
account_number: '55779911'
|
419
|
+
)
|
420
|
+
iban.iban # => "GB60BARC20000055779911"
|
414
421
|
```
|
415
422
|
|
416
423
|
## Other libraries
|
data/lib/ibandit/check_digit.rb
CHANGED
@@ -102,6 +102,23 @@ module Ibandit
|
|
102
102
|
result < 10 ? result.to_s : '0'
|
103
103
|
end
|
104
104
|
|
105
|
+
# Currently unused in this gem. This method calculates the last digit
|
106
|
+
# of a Croatian account number when given the initial digits.
|
107
|
+
def self.croatian(string)
|
108
|
+
calculation = string.chars.map.reduce(10) do |total, char|
|
109
|
+
unless char.to_i.to_s == char
|
110
|
+
raise InvalidCharacterError,
|
111
|
+
"Unexpected non-numeric character '#{char}'"
|
112
|
+
end
|
113
|
+
|
114
|
+
calc = (char.to_i + total) % 10
|
115
|
+
calc = calc == 0 ? 10 : calc
|
116
|
+
(calc * 2) % 11
|
117
|
+
end
|
118
|
+
|
119
|
+
((11 - calculation) % 10).to_s
|
120
|
+
end
|
121
|
+
|
105
122
|
# Currently unused in this gem. This method calculates the penultimate digit
|
106
123
|
# of an Icelandic kennitala (included in the account number) when given the
|
107
124
|
# first 8 digits.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Ibandit
|
2
2
|
module IBANAssembler
|
3
|
-
SUPPORTED_COUNTRY_CODES = %w(AT BE BG CY DE DK EE ES FI FR GB GR HU IE
|
4
|
-
LT LU LV MC MT NL NO PL PT RO SE SI SK
|
3
|
+
SUPPORTED_COUNTRY_CODES = %w(AT BE BG CY CZ DE DK EE ES FI FR GB GR HR HU IE
|
4
|
+
IS IT LT LU LV MC MT NL NO PL PT RO SE SI SK
|
5
5
|
SM).freeze
|
6
6
|
|
7
7
|
EXCEPTION_COUNTRY_CODES = %w(IT SM BE).freeze
|
@@ -85,7 +85,7 @@ module Ibandit
|
|
85
85
|
|
86
86
|
def self.required_fields(country_code)
|
87
87
|
case country_code
|
88
|
-
when *%w(AT CY DE DK EE FI IS LT LU LV NL NO PL RO SE SI SK)
|
88
|
+
when *%w(AT CY CZ DE DK EE FI HR IS LT LU LV NL NO PL RO SE SI SK)
|
89
89
|
%i(bank_code account_number)
|
90
90
|
when 'BE'
|
91
91
|
%i(account_number)
|
@@ -100,7 +100,7 @@ module Ibandit
|
|
100
100
|
when 'BE' then %i(bank_code account_number)
|
101
101
|
when 'CY' then %i(bank_code branch_code account_number)
|
102
102
|
when 'IT' then %i(bank_code branch_code account_number check_digit)
|
103
|
-
when 'SK' then %i(bank_code account_number account_number_prefix)
|
103
|
+
when 'CZ', 'SK' then %i(bank_code account_number account_number_prefix)
|
104
104
|
else required_fields(country_code)
|
105
105
|
end
|
106
106
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Ibandit
|
2
2
|
module LocalDetailsCleaner
|
3
|
-
SUPPORTED_COUNTRY_CODES = %w(AT BE BG CY DE DK EE ES FI FR GB GR HU IE
|
4
|
-
LT LU LV MC MT NL NO PL PT RO SE SI SK
|
3
|
+
SUPPORTED_COUNTRY_CODES = %w(AT BE BG CY CZ DE DK EE ES FI FR GB GR HR HU IE
|
4
|
+
IS IT LT LU LV MC MT NL NO PL PT RO SE SI SK
|
5
5
|
SM).freeze
|
6
6
|
|
7
7
|
def self.clean(local_details)
|
@@ -30,7 +30,7 @@ module Ibandit
|
|
30
30
|
case country_code
|
31
31
|
when 'AT', 'CY', 'DE', 'FI', 'LT', 'LU', 'LV', 'NL', 'RO', 'SI', 'SK'
|
32
32
|
%i(bank_code account_number)
|
33
|
-
when 'BE', 'DK', 'EE', 'ES', 'HU', 'IS', 'NO', 'PL', 'SE'
|
33
|
+
when 'BE', 'CZ', 'DK', 'EE', 'ES', 'HR', 'HU', 'IS', 'NO', 'PL', 'SE'
|
34
34
|
%i(account_number)
|
35
35
|
when 'GB', 'IE', 'MT'
|
36
36
|
if Ibandit.bic_finder.nil? then %i(bank_code branch_code account_number)
|
@@ -95,6 +95,26 @@ module Ibandit
|
|
95
95
|
}
|
96
96
|
end
|
97
97
|
|
98
|
+
def self.clean_cz_details(local_details)
|
99
|
+
# The SWIFT definition of a Czech IBAN includes both the account
|
100
|
+
# number prefix and the account number. This method therefore supports
|
101
|
+
# passing those fields concatenated.
|
102
|
+
account_number =
|
103
|
+
if local_details.include?(:account_number_prefix)
|
104
|
+
[
|
105
|
+
local_details[:account_number_prefix].rjust(6, '0'),
|
106
|
+
local_details[:account_number].rjust(10, '0')
|
107
|
+
].join
|
108
|
+
else
|
109
|
+
local_details[:account_number].tr('-', '').rjust(16, '0')
|
110
|
+
end
|
111
|
+
|
112
|
+
{
|
113
|
+
bank_code: local_details[:bank_code],
|
114
|
+
account_number: account_number
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
98
118
|
def self.clean_de_details(local_details)
|
99
119
|
# Account number may be up to 10 digits long.
|
100
120
|
# Add leading zeros to account number if < 10 digits.
|
@@ -233,6 +253,20 @@ module Ibandit
|
|
233
253
|
local_details
|
234
254
|
end
|
235
255
|
|
256
|
+
def self.clean_hr_details(local_details)
|
257
|
+
# This method supports being passed the component IBAN parts, as defined
|
258
|
+
# by SWIFT, or a single traditional-format string split by a '-'.
|
259
|
+
return local_details if local_details[:bank_code]
|
260
|
+
return local_details unless local_details[:account_number].include?('-')
|
261
|
+
|
262
|
+
bank_code, account_number = local_details[:account_number].split('-', 2)
|
263
|
+
|
264
|
+
{
|
265
|
+
bank_code: bank_code,
|
266
|
+
account_number: account_number
|
267
|
+
}
|
268
|
+
end
|
269
|
+
|
236
270
|
def self.clean_hu_details(local_details)
|
237
271
|
# This method supports being passed the component IBAN parts, as defined
|
238
272
|
# by SWIFT, or a single 16 or 24 digit string.
|
@@ -423,23 +457,8 @@ module Ibandit
|
|
423
457
|
end
|
424
458
|
|
425
459
|
def self.clean_sk_details(local_details)
|
426
|
-
#
|
427
|
-
|
428
|
-
# passing those fields concatenated.
|
429
|
-
account_number =
|
430
|
-
if local_details.include?(:account_number_prefix)
|
431
|
-
[
|
432
|
-
local_details[:account_number_prefix].rjust(6, '0'),
|
433
|
-
local_details[:account_number].rjust(10, '0')
|
434
|
-
].join
|
435
|
-
else
|
436
|
-
local_details[:account_number].tr('-', '').rjust(16, '0')
|
437
|
-
end
|
438
|
-
|
439
|
-
{
|
440
|
-
bank_code: local_details[:bank_code],
|
441
|
-
account_number: account_number
|
442
|
-
}
|
460
|
+
# Slovakia uses the same local details method as the Czech Republic
|
461
|
+
clean_cz_details(local_details)
|
443
462
|
end
|
444
463
|
|
445
464
|
def self.clean_sm_details(local_details)
|
data/lib/ibandit/version.rb
CHANGED
@@ -126,6 +126,28 @@ describe Ibandit::CheckDigit do
|
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
+
describe '.croatian' do
|
130
|
+
subject { described_class.croatian(account_number) }
|
131
|
+
|
132
|
+
let(:account_number) { '0823' }
|
133
|
+
it { is_expected.to eq('5') }
|
134
|
+
|
135
|
+
context 'with another account number (double checking!)' do
|
136
|
+
let(:account_number) { '100100' }
|
137
|
+
it { is_expected.to eq('5') }
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'with all zeros' do
|
141
|
+
let(:account_number) { '186300016' }
|
142
|
+
it { is_expected.to eq('0') }
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'with a non-numeric character' do
|
146
|
+
let(:account_number) { '1BAD2014' }
|
147
|
+
specify { expect { subject }.to raise_error(/non-numeric character/) }
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
129
151
|
describe '.icelandic' do
|
130
152
|
subject { described_class.icelandic(kennitala) }
|
131
153
|
|
@@ -123,6 +123,30 @@ describe Ibandit::IBANAssembler do
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
+
context 'with CZ as the country_code' do
|
127
|
+
let(:args) do
|
128
|
+
{
|
129
|
+
country_code: 'CZ',
|
130
|
+
bank_code: '0800',
|
131
|
+
account_number: '0000192000145399'
|
132
|
+
}
|
133
|
+
end
|
134
|
+
|
135
|
+
it { is_expected.to eq('CZ6508000000192000145399') }
|
136
|
+
|
137
|
+
it_behaves_like 'allows round trips', 'CZ65 0800 0000 1920 0014 5399'
|
138
|
+
|
139
|
+
context 'without a bank_code' do
|
140
|
+
before { args.delete(:bank_code) }
|
141
|
+
it { is_expected.to be_nil }
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'without an account_number' do
|
145
|
+
before { args.delete(:account_number) }
|
146
|
+
it { is_expected.to be_nil }
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
126
150
|
context 'with DE as the country_code' do
|
127
151
|
let(:args) do
|
128
152
|
{ country_code: 'DE',
|
@@ -339,6 +363,28 @@ describe Ibandit::IBANAssembler do
|
|
339
363
|
end
|
340
364
|
end
|
341
365
|
|
366
|
+
context 'with HR as the country_code' do
|
367
|
+
let(:args) do
|
368
|
+
{ country_code: 'HR',
|
369
|
+
bank_code: '1001005',
|
370
|
+
account_number: '1863000160' }
|
371
|
+
end
|
372
|
+
|
373
|
+
it { is_expected.to eq('HR1210010051863000160') }
|
374
|
+
|
375
|
+
it_behaves_like 'allows round trips', 'HR12 1001 0051 8630 0016 0'
|
376
|
+
|
377
|
+
context 'without a bank_code' do
|
378
|
+
before { args.delete(:bank_code) }
|
379
|
+
it { is_expected.to be_nil }
|
380
|
+
end
|
381
|
+
|
382
|
+
context 'without an account_number' do
|
383
|
+
before { args.delete(:account_number) }
|
384
|
+
it { is_expected.to be_nil }
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
342
388
|
context 'with HU as the country_code' do
|
343
389
|
let(:args) do
|
344
390
|
{
|
@@ -152,6 +152,37 @@ describe Ibandit::LocalDetailsCleaner do
|
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
155
|
+
context 'Czech Republic' do
|
156
|
+
let(:country_code) { 'CZ' }
|
157
|
+
let(:bank_code) { '0800' }
|
158
|
+
let(:account_number) { '0000192000145399' }
|
159
|
+
|
160
|
+
it { is_expected.to eq(local_details) }
|
161
|
+
|
162
|
+
context 'with an account number prefix' do
|
163
|
+
let(:prefix) { '000019' }
|
164
|
+
let(:account_number) { '2000145399' }
|
165
|
+
before { local_details.merge!(account_number_prefix: prefix) }
|
166
|
+
|
167
|
+
its([:account_number]) { is_expected.to eq('0000192000145399') }
|
168
|
+
|
169
|
+
context 'which needs zero-padding' do
|
170
|
+
let(:prefix) { '19' }
|
171
|
+
its([:account_number]) { is_expected.to eq('0000192000145399') }
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context 'without a bank code' do
|
176
|
+
let(:bank_code) { nil }
|
177
|
+
it { is_expected.to eq(local_details) }
|
178
|
+
end
|
179
|
+
|
180
|
+
context 'without an account number' do
|
181
|
+
let(:account_number) { nil }
|
182
|
+
it { is_expected.to eq(local_details) }
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
155
186
|
context 'Germany' do
|
156
187
|
let(:country_code) { 'DE' }
|
157
188
|
let(:bank_code) { '37040044' }
|
@@ -422,6 +453,33 @@ describe Ibandit::LocalDetailsCleaner do
|
|
422
453
|
end
|
423
454
|
end
|
424
455
|
|
456
|
+
context 'Croatia' do
|
457
|
+
let(:country_code) { 'HR' }
|
458
|
+
let(:bank_code) { '1001005' }
|
459
|
+
let(:account_number) { '1863000160' }
|
460
|
+
|
461
|
+
it { is_expected.to eq(local_details) }
|
462
|
+
|
463
|
+
context 'with bank code in the account number' do
|
464
|
+
let(:bank_code) { nil }
|
465
|
+
let(:branch_code) { nil }
|
466
|
+
let(:account_number) { '1001005-1863000160' }
|
467
|
+
|
468
|
+
its([:bank_code]) { is_expected.to eq('1001005') }
|
469
|
+
its([:account_number]) { is_expected.to eq('1863000160') }
|
470
|
+
|
471
|
+
context 'with a badly formatted account number' do
|
472
|
+
let(:account_number) { '1863000160' }
|
473
|
+
it { is_expected.to eq(local_details) }
|
474
|
+
end
|
475
|
+
end
|
476
|
+
|
477
|
+
context 'without an account number' do
|
478
|
+
let(:account_number) { nil }
|
479
|
+
it { is_expected.to eq(local_details) }
|
480
|
+
end
|
481
|
+
end
|
482
|
+
|
425
483
|
context 'Hungary' do
|
426
484
|
let(:country_code) { 'HU' }
|
427
485
|
let(:bank_code) { '117' }
|
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
|
+
version: 0.6.6
|
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-
|
11
|
+
date: 2015-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|