ibanizator 0.3.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/iban/validator.rb +0 -8
- data/lib/ibanizator.rb +8 -28
- data/lib/ibanizator/bank_db.rb +39 -15
- data/lib/ibanizator/iban.rb +4 -0
- data/lib/ibanizator/iban/extended_data/de.rb +22 -2
- metadata +15 -15
- data/lib/swift_bic/bank_db.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b015729f9d4eaf5a14f69b1d930930f9b41dc9672824081e4e4682b1f2c67918
|
4
|
+
data.tar.gz: 1a9670039e52ed73c62b758f3b7d383955ebf4f932f3e8c103167256874f86d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a796a55437bd6811ac03243bbcf5e569753a980f0362b3de9845de9f76a6c44ce20f90bb1dcfe8405789856984a3fa4f1ed644ab3485e8b4195dc2faee4f0060
|
7
|
+
data.tar.gz: ab68994a1f0e1f95c4b0e7dca633b38a28c58e71e77d2406aae2646af25baca7f050cf3ad71d0989c7664f2bda211c35a00ef6002c3b5be3e921d7a273320792
|
data/lib/iban/validator.rb
CHANGED
@@ -1,13 +1,5 @@
|
|
1
1
|
module Iban
|
2
2
|
class Validator
|
3
|
-
# <b>DEPRECATED:</b> Please use <tt>Ibanizator.iban_from_string(an_iban).valid?</tt> instead.
|
4
|
-
def validate_iban(input)
|
5
|
-
warn "[DEPRECATION] `Iban#validate_iban` is deprecated. Please use `Ibanizator.iban_from_string(an_iban).valid?instead."
|
6
|
-
iban = sanitize_input(input)
|
7
|
-
|
8
|
-
valid_length?(iban) && valid_checksum?(iban)
|
9
|
-
end
|
10
|
-
|
11
3
|
# public because it's used in `Ibanizator.calculate_iban`
|
12
4
|
def sanitize_input(input)
|
13
5
|
input.to_s.chomp.gsub(/\s+/,"")
|
data/lib/ibanizator.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'iban/validator'
|
2
|
-
require_relative 'swift_bic/bank_db'
|
3
4
|
|
4
5
|
require_relative 'ibanizator/bank_db'
|
5
6
|
require_relative 'ibanizator/bank'
|
6
7
|
require_relative 'ibanizator/iban'
|
7
8
|
|
8
9
|
class Ibanizator
|
9
|
-
|
10
10
|
def self.bank_db
|
11
11
|
@bank_db ||= BankDb.new
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.iban_from_string(
|
15
|
-
Iban.from_string(
|
14
|
+
def self.iban_from_string(string)
|
15
|
+
Iban.from_string(string)
|
16
16
|
end
|
17
17
|
|
18
|
-
def calculate_iban
|
18
|
+
def calculate_iban(options)
|
19
19
|
# Error handling
|
20
20
|
# TODO
|
21
21
|
|
@@ -34,34 +34,14 @@ class Ibanizator
|
|
34
34
|
options[:country_code].to_s.upcase + checksum + options[:bank_code] + options[:account_number]
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
|
-
def validate_iban iban
|
39
|
-
warn "[DEPRECATION] `Ibanizator#validate_iban` is deprecated. Please use `Ibanizator.iban_from_string(an_iban).valid?instead."
|
40
|
-
# for the sake of compatibility
|
41
|
-
self.class.iban_from_string(iban).valid?
|
42
|
-
end
|
43
|
-
|
44
|
-
# <b>DEPRECATED:</b> Please use <tt>Ibanizator.bank_db.bank_by_bank_code</tt> instead.
|
45
|
-
def bic bank_code
|
46
|
-
warn "[DEPRECATION] `Ibanizator#bank_name` is deprecated. Please use `Ibanizator::bank_db.bank_by_bank_code` instead."
|
47
|
-
bank_db = SwiftBic::BankDb.new bank_code
|
48
|
-
bank_db.bic
|
49
|
-
end
|
50
|
-
|
51
|
-
# <b>DEPRECATED:</b> Please use <tt>Ibanizator.bank_db.bank_by_bank_code</tt> instead.
|
52
|
-
def bank_name bank_code
|
53
|
-
warn "[DEPRECATION] `Ibanizator#bank_name` is deprecated. Please use `Ibanizator::bank_db.bank_by_bank_code` instead."
|
54
|
-
bank_db = SwiftBic::BankDb.new bank_code
|
55
|
-
bank_db.bank_name
|
56
|
-
end
|
57
|
-
|
58
|
-
def character_to_digit char
|
37
|
+
def character_to_digit(char)
|
59
38
|
char.upcase.split('').inject('') { |code, c| code + (c.ord - 55).to_s }
|
60
39
|
end
|
61
40
|
|
62
|
-
def calculate_checksum
|
41
|
+
def calculate_checksum(bank_code, account_number, country_code_num)
|
63
42
|
x = (bank_code + account_number + country_code_num + '00').to_i % 97
|
64
43
|
checksum = (98 - x).to_s
|
44
|
+
|
65
45
|
checksum.length == 1 ? checksum.insert(0, '0') : checksum
|
66
46
|
end
|
67
47
|
end
|
data/lib/ibanizator/bank_db.rb
CHANGED
@@ -1,46 +1,70 @@
|
|
1
1
|
class Ibanizator
|
2
2
|
class BankDb
|
3
|
-
class BankNotFoundError < StandardError
|
3
|
+
class BankNotFoundError < StandardError; end
|
4
4
|
|
5
|
-
attr_reader :known_banks
|
5
|
+
attr_reader :known_banks, :bank_code_index, :bic_index
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
@known_banks = []
|
9
|
-
@bic_index
|
9
|
+
@bic_index = {}
|
10
|
+
@bank_code_index = {}
|
10
11
|
populate_known_banks!
|
11
12
|
end
|
12
13
|
|
13
|
-
def bank_by_bic(
|
14
|
-
@bic_index.fetch(
|
15
|
-
error!
|
14
|
+
def bank_by_bic(bic)
|
15
|
+
@bic_index.fetch(bic.to_s) do
|
16
|
+
error!("No bank for bic: #{bic} found")
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
|
-
def bank_by_bank_code(
|
20
|
-
@bank_code_index.fetch(sanitize_bank_code(
|
21
|
-
error!
|
20
|
+
def bank_by_bank_code(bank_code)
|
21
|
+
@bank_code_index.fetch(sanitize_bank_code(bank_code)) do
|
22
|
+
error!("No bank for bank_code: #{bank_code} found")
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
26
|
private
|
27
|
+
|
26
28
|
def populate_known_banks!
|
27
|
-
File.
|
29
|
+
file = File.expand_path('../../db/blz.txt', __dir__)
|
30
|
+
|
31
|
+
File.open(file, 'r').each_line do |line|
|
28
32
|
code, _, _, _, _, name, _, bic = line.unpack 'A8A1A58A5A35A27A5A11'
|
29
33
|
next if bic.empty?
|
34
|
+
|
30
35
|
name.force_encoding('iso-8859-1').encode!('utf-8')
|
31
36
|
bank = Bank.new(bic, name, code)
|
32
|
-
|
33
|
-
|
34
|
-
@bank_code_index[bank.bank_code] = bank
|
37
|
+
|
38
|
+
add_bank_to_indices(bank)
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
38
|
-
def sanitize_bank_code(
|
39
|
-
|
42
|
+
def sanitize_bank_code(bank_code)
|
43
|
+
bank_code.to_s.gsub(/\s+/, '')
|
40
44
|
end
|
41
45
|
|
42
46
|
def error!(message)
|
43
47
|
raise BankNotFoundError, message
|
44
48
|
end
|
49
|
+
|
50
|
+
def add_bank_to_indices(bank)
|
51
|
+
@known_banks << bank
|
52
|
+
|
53
|
+
@bic_index[bank.bic] = bank
|
54
|
+
if optional_branch_code?(bank.bic)
|
55
|
+
@bic_index[bank.bic.gsub(/XXX$/, '')] = bank
|
56
|
+
end
|
57
|
+
|
58
|
+
return if bank_exists_and_not_favored?(bank.bank_code, bank.bic)
|
59
|
+
@bank_code_index[bank.bank_code] = bank
|
60
|
+
end
|
61
|
+
|
62
|
+
def optional_branch_code?(bic)
|
63
|
+
bic.end_with?('XXX')
|
64
|
+
end
|
65
|
+
|
66
|
+
def bank_exists_and_not_favored?(bank_code, bic)
|
67
|
+
@bank_code_index.key?(bank_code) && !optional_branch_code?(bic)
|
68
|
+
end
|
45
69
|
end
|
46
70
|
end
|
data/lib/ibanizator/iban.rb
CHANGED
@@ -22,9 +22,29 @@ class Ibanizator
|
|
22
22
|
memoize :account_number
|
23
23
|
|
24
24
|
def bic
|
25
|
-
|
25
|
+
bank.bic
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
|
+
def bank_name
|
29
|
+
bank.name
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_hash
|
33
|
+
{
|
34
|
+
bank_code: bank_code,
|
35
|
+
account_number: account_number,
|
36
|
+
bic: bic,
|
37
|
+
bank_name: bank_name,
|
38
|
+
}
|
39
|
+
end
|
40
|
+
alias_method :to_h, :to_hash
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def bank
|
45
|
+
Ibanizator.bank_db.bank_by_bank_code(bank_code)
|
46
|
+
end
|
47
|
+
memoize :bank
|
28
48
|
end
|
29
49
|
end # ExtendedData
|
30
50
|
end # Iban
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ibanizator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Julien Gantner
|
8
|
+
- David Seeherr
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2018-
|
12
|
+
date: 2018-07-01 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: adamantium
|
@@ -42,30 +43,30 @@ dependencies:
|
|
42
43
|
name: bundler
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
45
|
-
- - "
|
46
|
+
- - "~>"
|
46
47
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
48
|
+
version: '1.16'
|
48
49
|
type: :development
|
49
50
|
prerelease: false
|
50
51
|
version_requirements: !ruby/object:Gem::Requirement
|
51
52
|
requirements:
|
52
|
-
- - "
|
53
|
+
- - "~>"
|
53
54
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
+
version: '1.16'
|
55
56
|
- !ruby/object:Gem::Dependency
|
56
57
|
name: rake
|
57
58
|
requirement: !ruby/object:Gem::Requirement
|
58
59
|
requirements:
|
59
|
-
- - "
|
60
|
+
- - "~>"
|
60
61
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
+
version: '12.0'
|
62
63
|
type: :development
|
63
64
|
prerelease: false
|
64
65
|
version_requirements: !ruby/object:Gem::Requirement
|
65
66
|
requirements:
|
66
|
-
- - "
|
67
|
+
- - "~>"
|
67
68
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
+
version: '12.0'
|
69
70
|
- !ruby/object:Gem::Dependency
|
70
71
|
name: rspec
|
71
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,7 +85,7 @@ description: |2
|
|
84
85
|
ibanizator generates the correct IBAN for given account number and bank number
|
85
86
|
for german accounts. It is possible to validate given international IBANS.
|
86
87
|
Calculates also the BIC and bank names for given german bank codes.
|
87
|
-
email:
|
88
|
+
email: julien.gantner@softwareinmotion.de
|
88
89
|
executables: []
|
89
90
|
extensions: []
|
90
91
|
extra_rdoc_files: []
|
@@ -103,7 +104,6 @@ files:
|
|
103
104
|
- lib/ibanizator/iban/invalid.rb
|
104
105
|
- lib/ibanizator/iban/lengths.rb
|
105
106
|
- lib/ibanizator/iban/validator.rb
|
106
|
-
- lib/swift_bic/bank_db.rb
|
107
107
|
- license.md
|
108
108
|
homepage: https://github.com/softwareinmotion/ibanizator
|
109
109
|
licenses:
|
@@ -117,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
117
|
requirements:
|
118
118
|
- - ">="
|
119
119
|
- !ruby/object:Gem::Version
|
120
|
-
version:
|
120
|
+
version: 2.1.0
|
121
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
123
|
- - ">="
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
127
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.
|
128
|
+
rubygems_version: 2.7.6
|
129
129
|
signing_key:
|
130
130
|
specification_version: 4
|
131
131
|
summary: An IBAN generator/validator and BIC generator for german accounts.
|
data/lib/swift_bic/bank_db.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require_relative '../errors/invalid_bank_code_error'
|
2
|
-
require_relative '../errors/bank_not_found_error'
|
3
|
-
|
4
|
-
module SwiftBic
|
5
|
-
class BankDb
|
6
|
-
|
7
|
-
BANKS = {}.tap do |banks|
|
8
|
-
File.open(File.expand_path("../../../db/blz.txt", __FILE__), 'r').each_line do |line|
|
9
|
-
code, _, _, _, _, name, _, bic = line.unpack 'A8A1A58A5A35A27A5A11'
|
10
|
-
next if bic.empty?
|
11
|
-
name.force_encoding('iso-8859-1').encode!('utf-8')
|
12
|
-
banks[code] = [name, bic]
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# <b>DEPRECATED:</b> Please use <tt>Ibanizator.bank_db</tt> instead.
|
17
|
-
def initialize bank_code
|
18
|
-
warn "[DEPRECATION] `SwiftBic::BankDb` is deprecated. Please use `Ibanizator::bank_db` instead."
|
19
|
-
validate_bank_code bank_code
|
20
|
-
@bank_data = BANKS[bank_code]
|
21
|
-
raise BankNotFoundError unless @bank_data
|
22
|
-
end
|
23
|
-
|
24
|
-
def bank_name
|
25
|
-
@bank_data[0]
|
26
|
-
end
|
27
|
-
|
28
|
-
def bic
|
29
|
-
@bank_data[1]
|
30
|
-
end
|
31
|
-
|
32
|
-
def validate_bank_code bank_code
|
33
|
-
if bank_code.length == 8
|
34
|
-
return true
|
35
|
-
else
|
36
|
-
raise InvalidBankCodeError
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|