iso-iban 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/data/iso-iban/specs.yaml +19 -20
- data/iso-iban.gemspec +1 -1
- data/lib/iso/iban.rb +40 -0
- data/lib/iso/iban/specification.rb +8 -4
- data/lib/iso/iban/version.rb +1 -1
- data/test/unit/lib/iso/iban.rb +21 -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: 3d1b83f6a5ea9e59b2c0e67a3692481e59e37af2
|
4
|
+
data.tar.gz: ba05ced9a335ac538674ddcc7dc38a1f9d3ee5b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fe30f823be684f459cb21c772509c08da8959e8d95b52af05fe878564c172fc9702bf517b8d1840f9e33b7b804d55d84e2da828beba1858a83fe1b6c2d9f23e
|
7
|
+
data.tar.gz: 49db76377be9e9ddc86d46ca25007ad6bc3b077e5b3495cb7be20bb92b5d9711a20602c33047bead39b6a80e15a94fbad43d5c072ea0eeb9af6e03bd5ffc189f
|
data/data/iso-iban/specs.yaml
CHANGED
@@ -49,7 +49,7 @@ BH:
|
|
49
49
|
- BH2!n4!a14!c
|
50
50
|
- 22
|
51
51
|
- 4!a14!c
|
52
|
-
-
|
52
|
+
- 18
|
53
53
|
- 4
|
54
54
|
- 7
|
55
55
|
-
|
@@ -104,7 +104,7 @@ CR:
|
|
104
104
|
- CR2!n3!n14!n
|
105
105
|
- 21
|
106
106
|
- 3!n14!n
|
107
|
-
-
|
107
|
+
- 17
|
108
108
|
- 4
|
109
109
|
- 6
|
110
110
|
-
|
@@ -145,7 +145,7 @@ CZ:
|
|
145
145
|
DK:
|
146
146
|
- Denmark
|
147
147
|
- DK
|
148
|
-
- DK2!n4!n9!n1!n
|
148
|
+
- DK2!n4!n9!n1!n
|
149
149
|
- 18
|
150
150
|
- 4!n9!n1!n
|
151
151
|
- 14
|
@@ -156,7 +156,7 @@ DK:
|
|
156
156
|
FO:
|
157
157
|
- Denmark
|
158
158
|
- FO
|
159
|
-
-
|
159
|
+
- FO2!n4!n9!n1!n
|
160
160
|
- 18
|
161
161
|
- 4!n9!n1!n
|
162
162
|
- 14
|
@@ -167,7 +167,7 @@ FO:
|
|
167
167
|
GL:
|
168
168
|
- Denmark
|
169
169
|
- GL
|
170
|
-
-
|
170
|
+
- GL2!n4!n9!n1!n
|
171
171
|
- 18
|
172
172
|
- 4!n9!n1!n
|
173
173
|
- 14
|
@@ -202,8 +202,8 @@ FI:
|
|
202
202
|
- FI
|
203
203
|
- FI2!n6!n7!n1!n
|
204
204
|
- 18
|
205
|
-
-
|
206
|
-
-
|
205
|
+
- 6!n7!n1!n
|
206
|
+
- 14
|
207
207
|
- 4
|
208
208
|
- 6
|
209
209
|
-
|
@@ -367,7 +367,7 @@ DE:
|
|
367
367
|
- DE
|
368
368
|
- DE2!n8!n10!n
|
369
369
|
- 22
|
370
|
-
- 8!n10!n
|
370
|
+
- 8!n10!n
|
371
371
|
- 18
|
372
372
|
- 4
|
373
373
|
- 11
|
@@ -376,7 +376,7 @@ DE:
|
|
376
376
|
GI:
|
377
377
|
- Gibraltar
|
378
378
|
- GI
|
379
|
-
-
|
379
|
+
- GI2!n4!a15!c
|
380
380
|
- 23
|
381
381
|
- 4!a15!c
|
382
382
|
- 19
|
@@ -411,7 +411,7 @@ HU:
|
|
411
411
|
- HU
|
412
412
|
- HU2!n3!n4!n1!n15!n1!n
|
413
413
|
- 28
|
414
|
-
-
|
414
|
+
- 3!n4!n1!n15!n1!n
|
415
415
|
- 24
|
416
416
|
- 4
|
417
417
|
- 6
|
@@ -464,7 +464,7 @@ IT:
|
|
464
464
|
KW:
|
465
465
|
- Kuwait
|
466
466
|
- KW
|
467
|
-
- KW2!n4!a22!
|
467
|
+
- KW2!n4!a22!c
|
468
468
|
- 30
|
469
469
|
- 4!a22!c
|
470
470
|
- 26
|
@@ -475,9 +475,8 @@ KW:
|
|
475
475
|
KZ:
|
476
476
|
- Kazakhstan
|
477
477
|
- KZ
|
478
|
-
-
|
479
|
-
|
480
|
-
- 0
|
478
|
+
- KZ2!n3!n13!c
|
479
|
+
- 20
|
481
480
|
- 3!n13!c
|
482
481
|
- 16
|
483
482
|
- 4
|
@@ -512,7 +511,7 @@ LI:
|
|
512
511
|
- LI2!n5!n12!c
|
513
512
|
- 21
|
514
513
|
- 5!n12!c
|
515
|
-
-
|
514
|
+
- 17
|
516
515
|
- 4
|
517
516
|
- 8
|
518
517
|
-
|
@@ -564,7 +563,7 @@ MT:
|
|
564
563
|
MR:
|
565
564
|
- Mauritania
|
566
565
|
- MR
|
567
|
-
-
|
566
|
+
- MR2!n5!n5!n11!n2!n
|
568
567
|
- 27
|
569
568
|
- 5!n5!n11!n2!n
|
570
569
|
- 23
|
@@ -586,7 +585,7 @@ MU:
|
|
586
585
|
MD:
|
587
586
|
- Republic of Moldova
|
588
587
|
- MD
|
589
|
-
- MD2!
|
588
|
+
- MD2!n2!c18!c
|
590
589
|
- 24
|
591
590
|
- 2!c18!c
|
592
591
|
- 20
|
@@ -663,7 +662,7 @@ PS:
|
|
663
662
|
PL:
|
664
663
|
- Poland
|
665
664
|
- PL
|
666
|
-
- PL2!n8!
|
665
|
+
- PL2!n8!n16!n
|
667
666
|
- 28
|
668
667
|
- 8!n16!n
|
669
668
|
- 24
|
@@ -784,7 +783,7 @@ CH:
|
|
784
783
|
TN:
|
785
784
|
- Tunisia
|
786
785
|
- TN
|
787
|
-
-
|
786
|
+
- TN2!n2!n3!n13!n2!n
|
788
787
|
- 24
|
789
788
|
- 2!n3!n13!n2!n
|
790
789
|
- 20
|
@@ -806,7 +805,7 @@ TR:
|
|
806
805
|
AE:
|
807
806
|
- United Arab Emirates
|
808
807
|
- AE
|
809
|
-
-
|
808
|
+
- AE2!n3!n16!n
|
810
809
|
- 23
|
811
810
|
- 3!n16!n
|
812
811
|
- 19
|
data/iso-iban.gemspec
CHANGED
data/lib/iso/iban.rb
CHANGED
@@ -61,6 +61,18 @@ module ISO
|
|
61
61
|
# (digits-only) form
|
62
62
|
CharacterCodes = Hash[('0'..'9').zip('0'..'9')+('a'..'z').zip(10..35)+('A'..'Z').zip(10..35)]
|
63
63
|
|
64
|
+
# All uppercase letters
|
65
|
+
UpperAlpha = [*'A'..'Z']
|
66
|
+
|
67
|
+
# All lowercase letters
|
68
|
+
LowerAlpha = [*'a'..'z']
|
69
|
+
|
70
|
+
# All digits
|
71
|
+
Digits = [*'0'..'9']
|
72
|
+
|
73
|
+
# All uppercase letters, lowercase letters and digits
|
74
|
+
AlphaNumeric = [*'A'..'Z', *'a'..'z', *'0'..'9']
|
75
|
+
|
64
76
|
# All specifications, see ISO::IBAN::Specification
|
65
77
|
@specifications = nil
|
66
78
|
|
@@ -160,6 +172,34 @@ module ISO
|
|
160
172
|
iban
|
161
173
|
end
|
162
174
|
|
175
|
+
# @param [String] countries
|
176
|
+
# A list of 2 letter country codes. If empty, all countries in
|
177
|
+
# ISO::IBAN::specifications are used.
|
178
|
+
#
|
179
|
+
# @return [ISO::IBAN] A random, valid IBAN
|
180
|
+
def self.random(*countries)
|
181
|
+
countries = specifications.keys if countries.empty?
|
182
|
+
country = countries.sample
|
183
|
+
account = specification(country).iban_structure.scan(/([A-Z]+)|(\d+)(!?)([nac])/).map { |exact, length, fixed, code|
|
184
|
+
if exact
|
185
|
+
exact
|
186
|
+
elsif code == 'a'
|
187
|
+
Array.new(length.to_i) { UpperAlpha.sample }.join('')
|
188
|
+
elsif code == 'c'
|
189
|
+
Array.new(length.to_i) { AlphaNumeric.sample }.join('')
|
190
|
+
elsif code == 'e'
|
191
|
+
' '*length.to_i
|
192
|
+
elsif code == 'n'
|
193
|
+
Array.new(length.to_i) { Digits.sample }.join('')
|
194
|
+
end
|
195
|
+
}.join('')
|
196
|
+
account[2,2] = '??'
|
197
|
+
iban = new(account)
|
198
|
+
iban.update_checksum!
|
199
|
+
|
200
|
+
iban
|
201
|
+
end
|
202
|
+
|
163
203
|
# Converts a String into its digits-only form, i.e. all characters a-z are replaced with their corresponding
|
164
204
|
# digit sequences, according to the IBAN specification.
|
165
205
|
#
|
@@ -23,20 +23,24 @@ module ISO
|
|
23
23
|
Hash[YAML.load_file(path).map { |country, spec| [country, new(*spec)] }]
|
24
24
|
end
|
25
25
|
|
26
|
-
# Parse the SWIFT provided file (which sadly is a mess).
|
26
|
+
# Parse the SWIFT provided file (which sadly is a huge mess and not machine friendly at all).
|
27
27
|
#
|
28
28
|
# @return [Array<ISO::IBAN::Specification>] an array with all specifications.
|
29
29
|
def self.parse_file(path)
|
30
30
|
File.read(path, encoding: Encoding::Windows_1252).encode(Encoding::UTF_8).split("\r\n").tap(&:shift).flat_map { |line|
|
31
|
-
country_name, country_codes,
|
32
|
-
codes
|
31
|
+
country_name, country_codes, iban_structure_raw, iban_length, bban_structure, bban_length, bank_position = line.split(/\t/).values_at(0,1,11,12,4,5,6)
|
32
|
+
codes = country_codes.size == 2 ? [country_codes] : country_codes.scan(/\b[A-Z]{2}\b/)
|
33
|
+
primary_code = codes.first
|
33
34
|
bank_position_from, bank_position_to, branch_position_from, branch_position_to = bank_position.match(/(?:[Pp]ositions?|) (\d+)-(\d+)(?:.*Branch identifier positions?: (\d+)-(\d+))?/).captures.map { |pos| pos && pos.to_i+3 }
|
34
35
|
|
35
36
|
codes.map { |a2_country_code|
|
37
|
+
iban_structure = iban_structure_raw[/#{a2_country_code}[acen\!\d]*/] || iban_structure_raw[/#{primary_code}[acen\!\d]*/]
|
38
|
+
bban_structure = bban_structure[/[acen\!\d]*/]
|
39
|
+
|
36
40
|
new(
|
37
41
|
country_name.strip,
|
38
42
|
a2_country_code,
|
39
|
-
iban_structure
|
43
|
+
iban_structure,
|
40
44
|
iban_length.to_i,
|
41
45
|
bban_structure.strip,
|
42
46
|
bban_length.to_i,
|
data/lib/iso/iban/version.rb
CHANGED
data/test/unit/lib/iso/iban.rb
CHANGED
@@ -7,6 +7,27 @@ suite "ISO::IBAN" do
|
|
7
7
|
ISO::IBAN.instance_variable_set(:@specifications, {'CH' => ISO::IBAN::Specification.new("Switzerland", "CH", "CH2!n5!n12!c", 21, "5!n12!c", 17, 4, 8, nil, nil)})
|
8
8
|
end
|
9
9
|
|
10
|
+
# since the specs provided by swift are a mess, we do a sanity check
|
11
|
+
test 'Specifications provided by SWIFT' do
|
12
|
+
ISO::IBAN.load_specifications
|
13
|
+
ISO::IBAN.specifications.each do |country, spec|
|
14
|
+
structure_length = spec.iban_structure.scan(/([A-Z]+)|(\d+)(!?)([nac])/).map { |exact, length, fixed, code|
|
15
|
+
exact ? exact.length : length.to_i
|
16
|
+
}.inject(:+)
|
17
|
+
|
18
|
+
assert_equal spec.iban_length, structure_length, "Spec for country #{country} is invalid, invalid length"
|
19
|
+
assert_equal spec.bban_structure, spec.iban_structure[5..-1], "Spec for country #{country} is invalid, iban differs from country + 2!n + bban"
|
20
|
+
assert_equal spec.bban_length, spec.iban_length-4, "Spec for country #{country} is invalid, iban length differs from bban length + 4"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'Random IBAN generation' do
|
25
|
+
ISO::IBAN.load_specifications
|
26
|
+
ISO::IBAN.specifications.each do |country, spec|
|
27
|
+
assert ISO::IBAN.random(country).valid?, "Random IBAN generator for country #{country} is invalid"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
10
31
|
test 'ISO::IBAN::generate problem, TODO' do
|
11
32
|
ISO::IBAN.instance_variable_set(:@specifications, {'BG' => ISO::IBAN::Specification.new("Bulgaria", "BG", "BG2!n4!a4!n2!n8!c", 22, "4!a4!n2!n8!c", 18, 4, 7, 8, 11)})
|
12
33
|
assert ISO::IBAN.generate('BG', 'AAAA', '2', 'C').valid? # this works now
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iso-iban
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Rusterholz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
ISO::IBAN implements IBAN (International Bank Account Number) specification as per ISO 13616-1.
|