ibanizator 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -7
- data/lib/iban/validator.rb +3 -3
- data/lib/ibanizator/bank_db.rb +2 -0
- data/lib/ibanizator/iban/extended_data/de.rb +31 -0
- data/lib/ibanizator/iban/extended_data.rb +10 -0
- data/lib/ibanizator/iban/invalid.rb +6 -0
- data/lib/ibanizator/iban/lengths.rb +71 -0
- data/lib/ibanizator/iban/validator.rb +37 -0
- data/lib/ibanizator/iban.rb +46 -0
- data/lib/ibanizator.rb +12 -5
- metadata +7 -2
- data/lib/iban/lengths.rb +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80f3e9fb535d2e6919de65a9edbedbde43ea2277
|
4
|
+
data.tar.gz: 7c75a0460dc326a4bf404daf231f0b5f7f427f11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 394f6e0642c5589d19d0013f5fe72469488e459c2e95034cdc835a9c3282002a8ae08338bb103bbb79853137974e2c4f8009e7c681baacb7a50dfb235a7d899c
|
7
|
+
data.tar.gz: 491636beb8fed35fc402bf717cc86a2a55585ded14d046519978ea85bd1c8aed8578ea6915a6e231a6d531a2eda97e1069669908677770ce37f91bf09510e845
|
data/README.md
CHANGED
@@ -20,21 +20,32 @@ To calculate the iban for some german accounts, just use this method:
|
|
20
20
|
|
21
21
|
In the current version the ibanizator gem only works for german accounts.
|
22
22
|
|
23
|
-
### Validate IBAN
|
23
|
+
### Validate an IBAN
|
24
24
|
|
25
25
|
To validate the iban you need to check the length and after this check the checksum. For details please refer to
|
26
26
|
the documentation online (e.g. http://es.wikipedia.org/wiki/IBAN).
|
27
27
|
|
28
|
-
This gem provides a simple validator for several contries. All countries that are listed in the Iban::LENGTHS hash are supported at the moment.
|
28
|
+
This gem provides a simple validator for several contries. All countries that are listed in the Ibanizator::Iban::LENGTHS hash are supported at the moment.
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
```ruby
|
31
|
+
iban = Ibanizator.iban_form_string("DE68 2105 0170 0012 3456 78")
|
32
|
+
iban.valid? # => true
|
33
|
+
```
|
32
34
|
|
33
|
-
|
35
|
+
### Information provided by an IBAN
|
34
36
|
|
35
|
-
|
37
|
+
The Ibanizator::Iban class provides some handy utility methods to query
|
38
|
+
information about an iban.
|
36
39
|
|
37
|
-
|
40
|
+
```ruby
|
41
|
+
iban = Ibanizator.iban_form_string("DE68 2105 0170 0012 3456 78")
|
42
|
+
iban.country_code # => :DE
|
43
|
+
|
44
|
+
# there is extended data for german ibans
|
45
|
+
iban.extended_data.bank_code # => "21050170"
|
46
|
+
iban.extended_data.account_number # => "12345678"
|
47
|
+
iban.extended_data.bic # => "NOLADE21KIE"
|
48
|
+
```
|
38
49
|
|
39
50
|
### Find bank infos
|
40
51
|
|
data/lib/iban/validator.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require_relative 'lengths'
|
2
|
-
|
3
1
|
module Iban
|
4
2
|
class Validator
|
3
|
+
# <b>DEPRECATED:</b> Please use <tt>Ibanizator.iban_from_string(an_iban).valid?</tt> instead.
|
5
4
|
def validate_iban(input)
|
5
|
+
warn "[DEPRECATION] `Iban#validate_iban` is deprecated. Please use `Ibanizator.iban_from_string(an_iban).valid?instead."
|
6
6
|
iban = sanitize_input(input)
|
7
7
|
|
8
8
|
valid_length?(iban) && valid_checksum?(iban)
|
@@ -18,7 +18,7 @@ module Iban
|
|
18
18
|
def valid_length?(iban)
|
19
19
|
return false if iban.length <= 4 # two digits for the country code and two for the checksum
|
20
20
|
country_code = iban[0..1].upcase.to_sym
|
21
|
-
iban.length == LENGTHS[country_code]
|
21
|
+
iban.length == Ibanizator::Iban::LENGTHS[country_code]
|
22
22
|
end
|
23
23
|
|
24
24
|
def valid_checksum?(iban)
|
data/lib/ibanizator/bank_db.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
class Ibanizator
|
2
|
+
class Iban
|
3
|
+
module ExtendedData
|
4
|
+
class DE
|
5
|
+
attr_reader :iban
|
6
|
+
include Equalizer.new(:iban)
|
7
|
+
include Adamantium
|
8
|
+
|
9
|
+
def initialize(iban)
|
10
|
+
raise Invalid, "can't compute extended data on invalid iban" unless iban.valid?
|
11
|
+
@iban = iban
|
12
|
+
end
|
13
|
+
|
14
|
+
def bank_code
|
15
|
+
iban.to_s[4..11]
|
16
|
+
end
|
17
|
+
memoize :bank_code
|
18
|
+
|
19
|
+
def account_number
|
20
|
+
iban.to_s[12..-1].gsub(/\A0+/,"")
|
21
|
+
end
|
22
|
+
memoize :account_number
|
23
|
+
|
24
|
+
def bic
|
25
|
+
Ibanizator.bank_db.bank_by_bank_code(bank_code).bic
|
26
|
+
end
|
27
|
+
memoize :bic
|
28
|
+
end
|
29
|
+
end # ExtendedData
|
30
|
+
end # Iban
|
31
|
+
end # Ibanizator
|
@@ -0,0 +1,71 @@
|
|
1
|
+
class Ibanizator
|
2
|
+
class Iban
|
3
|
+
# according to wikipedia (http://en.wikipedia.org/wiki/IBAN)
|
4
|
+
LENGTHS = {
|
5
|
+
:AL => 28,
|
6
|
+
:AD => 24,
|
7
|
+
:AT => 20,
|
8
|
+
:AZ => 28,
|
9
|
+
:BH => 22,
|
10
|
+
:BE => 16,
|
11
|
+
:BA => 20,
|
12
|
+
:BR => 29,
|
13
|
+
:BG => 22,
|
14
|
+
:CR => 21,
|
15
|
+
:HR => 21,
|
16
|
+
:CY => 28,
|
17
|
+
:CZ => 24,
|
18
|
+
:DK => 18,
|
19
|
+
:DO => 28,
|
20
|
+
:EE => 20,
|
21
|
+
:FO => 18,
|
22
|
+
:FI => 18,
|
23
|
+
:FR => 27,
|
24
|
+
:GE => 22,
|
25
|
+
:DE => 22,
|
26
|
+
:GI => 23,
|
27
|
+
:GR => 27,
|
28
|
+
:GL => 18,
|
29
|
+
:GT => 28,
|
30
|
+
:HU => 28,
|
31
|
+
:IS => 26,
|
32
|
+
:IE => 22,
|
33
|
+
:IL => 23,
|
34
|
+
:IT => 27,
|
35
|
+
:KZ => 20,
|
36
|
+
:KW => 30,
|
37
|
+
:LV => 21,
|
38
|
+
:LB => 28,
|
39
|
+
:LI => 21,
|
40
|
+
:LT => 20,
|
41
|
+
:LU => 20,
|
42
|
+
:MK => 19,
|
43
|
+
:MT => 31,
|
44
|
+
:MR => 27,
|
45
|
+
:MU => 30,
|
46
|
+
:MC => 27,
|
47
|
+
:MD => 24,
|
48
|
+
:ME => 22,
|
49
|
+
:NL => 18,
|
50
|
+
:NO => 15,
|
51
|
+
:PK => 24,
|
52
|
+
:PS => 29,
|
53
|
+
:PL => 28,
|
54
|
+
:PT => 25,
|
55
|
+
:RO => 24,
|
56
|
+
:SM => 27,
|
57
|
+
:SA => 24,
|
58
|
+
:RS => 22,
|
59
|
+
:SK => 24,
|
60
|
+
:SI => 19,
|
61
|
+
:ES => 24,
|
62
|
+
:SE => 24,
|
63
|
+
:CH => 21,
|
64
|
+
:TN => 24,
|
65
|
+
:TR => 26,
|
66
|
+
:AE => 23,
|
67
|
+
:GB => 22,
|
68
|
+
:VG => 24
|
69
|
+
}.freeze
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class Ibanizator
|
2
|
+
class Iban
|
3
|
+
class Validator
|
4
|
+
attr_reader :iban
|
5
|
+
|
6
|
+
def initialize(iban)
|
7
|
+
@iban = iban.to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
def validate
|
11
|
+
valid_length? && valid_checksum?
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def valid_length?
|
16
|
+
return false if iban.length <= 4 # two digits for the country code and two for the checksum
|
17
|
+
country_code = iban[0..1].upcase.to_sym
|
18
|
+
iban.length == LENGTHS[country_code]
|
19
|
+
end
|
20
|
+
|
21
|
+
def valid_checksum?
|
22
|
+
number_representation = integerize(reorder(iban))
|
23
|
+
number_representation % 97 == 1
|
24
|
+
end
|
25
|
+
|
26
|
+
def reorder(iban)
|
27
|
+
"#{iban[4..-1]}#{iban[0..3]}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def integerize(iban)
|
31
|
+
iban.gsub(/[A-Z]/) do |match|
|
32
|
+
match.ord - 'A'.ord + 10
|
33
|
+
end.to_i
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end # Iban
|
37
|
+
end # Ibanizator
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'equalizer'
|
2
|
+
require 'adamantium'
|
3
|
+
|
4
|
+
require_relative 'iban/extended_data'
|
5
|
+
require_relative 'iban/lengths'
|
6
|
+
require_relative 'iban/validator'
|
7
|
+
|
8
|
+
class Ibanizator
|
9
|
+
class Iban
|
10
|
+
attr_reader :iban_string
|
11
|
+
alias_method :to_s, :iban_string
|
12
|
+
|
13
|
+
include Equalizer.new(:iban_string)
|
14
|
+
include Adamantium
|
15
|
+
|
16
|
+
def initialize(an_iban)
|
17
|
+
@iban_string = sanitize(an_iban)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.from_string(a_string)
|
21
|
+
new(a_string)
|
22
|
+
end
|
23
|
+
|
24
|
+
def country_code
|
25
|
+
cc = iban_string[0..1].to_sym
|
26
|
+
LENGTHS.keys.include?(cc) ? cc : :unknown
|
27
|
+
end
|
28
|
+
memoize :country_code
|
29
|
+
|
30
|
+
def extended_data
|
31
|
+
if country_code == :DE
|
32
|
+
ExtendedData::DE.new(self)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
memoize :extended_data
|
36
|
+
|
37
|
+
def valid?
|
38
|
+
Validator.new(self).validate
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def sanitize(input)
|
43
|
+
input.to_s.gsub(/\s+/,'').upcase
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/ibanizator.rb
CHANGED
@@ -1,21 +1,27 @@
|
|
1
1
|
require_relative 'iban/validator'
|
2
2
|
require_relative 'swift_bic/bank_db'
|
3
|
+
|
3
4
|
require_relative 'ibanizator/bank_db'
|
4
5
|
require_relative 'ibanizator/bank'
|
6
|
+
require_relative 'ibanizator/iban'
|
5
7
|
|
6
8
|
class Ibanizator
|
9
|
+
|
7
10
|
def self.bank_db
|
8
11
|
@bank_db ||= BankDb.new
|
9
12
|
end
|
10
13
|
|
14
|
+
def self.iban_from_string(a_string)
|
15
|
+
Iban.from_string(a_string)
|
16
|
+
end
|
17
|
+
|
11
18
|
def calculate_iban options
|
12
19
|
# Error handling
|
13
20
|
# TODO
|
14
21
|
|
15
22
|
# delete spaces
|
16
|
-
|
17
|
-
options[:
|
18
|
-
options[:bank_code] = validator.sanitize_input(options[:bank_code])
|
23
|
+
options[:account_number] = options[:account_number].to_s.gsub(/\s+/, '')
|
24
|
+
options[:bank_code] = options[:bank_code].to_s.gsub(/\s+/, '')
|
19
25
|
|
20
26
|
# Fill account number to 10 digits
|
21
27
|
while options[:account_number].size < 10 do
|
@@ -28,10 +34,11 @@ class Ibanizator
|
|
28
34
|
options[:country_code].to_s.upcase + checksum + options[:bank_code] + options[:account_number]
|
29
35
|
end
|
30
36
|
|
37
|
+
# <b>DEPRECATED:</b> Please use <tt>Ibanizator.iban_from_string(an_iban).valid?</tt> instead.
|
31
38
|
def validate_iban iban
|
39
|
+
warn "[DEPRECATION] `Ibanizator#validate_iban` is deprecated. Please use `Ibanizator.iban_from_string(an_iban).valid?instead."
|
32
40
|
# for the sake of compatibility
|
33
|
-
|
34
|
-
validator.validate_iban(iban)
|
41
|
+
self.class.iban_from_string(iban).valid?
|
35
42
|
end
|
36
43
|
|
37
44
|
# <b>DEPRECATED:</b> Please use <tt>Ibanizator.bank_db.bank_by_bank_code</tt> instead.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ibanizator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christoph Stettner
|
@@ -106,11 +106,16 @@ files:
|
|
106
106
|
- db/blz.txt
|
107
107
|
- lib/errors/bank_not_found_error.rb
|
108
108
|
- lib/errors/invalid_bank_code_error.rb
|
109
|
-
- lib/iban/lengths.rb
|
110
109
|
- lib/iban/validator.rb
|
111
110
|
- lib/ibanizator.rb
|
112
111
|
- lib/ibanizator/bank.rb
|
113
112
|
- lib/ibanizator/bank_db.rb
|
113
|
+
- lib/ibanizator/iban.rb
|
114
|
+
- lib/ibanizator/iban/extended_data.rb
|
115
|
+
- lib/ibanizator/iban/extended_data/de.rb
|
116
|
+
- lib/ibanizator/iban/invalid.rb
|
117
|
+
- lib/ibanizator/iban/lengths.rb
|
118
|
+
- lib/ibanizator/iban/validator.rb
|
114
119
|
- lib/swift_bic/bank_db.rb
|
115
120
|
- license.md
|
116
121
|
homepage: https://github.com/softwareinmotion/ibanizator
|
data/lib/iban/lengths.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
module Iban
|
2
|
-
# according to wikipedia (http://en.wikipedia.org/wiki/IBAN)
|
3
|
-
LENGTHS = {
|
4
|
-
:AL => 28,
|
5
|
-
:AD => 24,
|
6
|
-
:AT => 20,
|
7
|
-
:AZ => 28,
|
8
|
-
:BH => 22,
|
9
|
-
:BE => 16,
|
10
|
-
:BA => 20,
|
11
|
-
:BR => 29,
|
12
|
-
:BG => 22,
|
13
|
-
:CR => 21,
|
14
|
-
:HR => 21,
|
15
|
-
:CY => 28,
|
16
|
-
:CZ => 24,
|
17
|
-
:DK => 18,
|
18
|
-
:DO => 28,
|
19
|
-
:EE => 20,
|
20
|
-
:FO => 18,
|
21
|
-
:FI => 18,
|
22
|
-
:FR => 27,
|
23
|
-
:GE => 22,
|
24
|
-
:DE => 22,
|
25
|
-
:GI => 23,
|
26
|
-
:GR => 27,
|
27
|
-
:GL => 18,
|
28
|
-
:GT => 28,
|
29
|
-
:HU => 28,
|
30
|
-
:IS => 26,
|
31
|
-
:IE => 22,
|
32
|
-
:IL => 23,
|
33
|
-
:IT => 27,
|
34
|
-
:KZ => 20,
|
35
|
-
:KW => 30,
|
36
|
-
:LV => 21,
|
37
|
-
:LB => 28,
|
38
|
-
:LI => 21,
|
39
|
-
:LT => 20,
|
40
|
-
:LU => 20,
|
41
|
-
:MK => 19,
|
42
|
-
:MT => 31,
|
43
|
-
:MR => 27,
|
44
|
-
:MU => 30,
|
45
|
-
:MC => 27,
|
46
|
-
:MD => 24,
|
47
|
-
:ME => 22,
|
48
|
-
:NL => 18,
|
49
|
-
:NO => 15,
|
50
|
-
:PK => 24,
|
51
|
-
:PS => 29,
|
52
|
-
:PL => 28,
|
53
|
-
:PT => 25,
|
54
|
-
:RO => 24,
|
55
|
-
:SM => 27,
|
56
|
-
:SA => 24,
|
57
|
-
:RS => 22,
|
58
|
-
:SK => 24,
|
59
|
-
:SI => 19,
|
60
|
-
:ES => 24,
|
61
|
-
:SE => 24,
|
62
|
-
:CH => 21,
|
63
|
-
:TN => 24,
|
64
|
-
:TR => 26,
|
65
|
-
:AE => 23,
|
66
|
-
:GB => 22,
|
67
|
-
:VG => 24
|
68
|
-
}.freeze
|
69
|
-
end
|