ibanizator 0.2.0 → 0.2.1
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/README.md +71 -0
- data/lib/ibanizator/bank.rb +15 -0
- data/lib/ibanizator/bank_db.rb +44 -0
- data/license.md +21 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20719f6ac56b0b536446948da0e98540c02fb106
|
4
|
+
data.tar.gz: e18a2a4e3ab59f8c95a0e32f381edd2bf9b708d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66bf35e9cd503100af54b91d16fd6fbca0bc8ae9307ffa2c872dc3c5ceb829d2e7169c33b0da6eac89cd36a8505a63a2c18f2e149d68f7688982d830e1f5539f
|
7
|
+
data.tar.gz: 437677f6b0c14417c0a316a36d48e39195b437f5c51b68f13e311bbfe61c8f2645a1ec6c85a527cf04bbcbaa3661cf6efe6776b4526ead057866c879e78354ab
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# ibanizator [](https://travis-ci.org/softwareinmotion/ibanizator)
|
2
|
+
|
3
|
+
ibanizator calculates the iban for german accounts. The database that is used to convert a bank number to a
|
4
|
+
BIC is taken from [Deutsche Bundesbank](http://www.bundesbank.de/Redaktion/EN/Standardartikel/Tasks/Payment_systems/bank_sort_codes_download.html).
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'ibanizator'
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
### Calculate IBAN
|
15
|
+
|
16
|
+
To calculate the iban for some german accounts, just use this method:
|
17
|
+
|
18
|
+
ibanizator = Ibanizator.new
|
19
|
+
ibanizator.calculate_iban country_code: :de, bank_code: '12345678', account_number: '123456789'
|
20
|
+
|
21
|
+
In the current version the ibanizator gem only works for german accounts.
|
22
|
+
|
23
|
+
### Validate IBAN
|
24
|
+
|
25
|
+
To validate the iban you need to check the length and after this check the checksum. For details please refer to
|
26
|
+
the documentation online (e.g. http://es.wikipedia.org/wiki/IBAN).
|
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.
|
29
|
+
|
30
|
+
validator = Iban::Validator.new
|
31
|
+
valid = validator.validate_iban("DE68 2105 0170 0012 3456 78") # => true
|
32
|
+
|
33
|
+
There is an alternate way to validate an IBAN as a result of the 0.0.1 Version:
|
34
|
+
|
35
|
+
ibanizator.validate_iban("DE68 2105 0170 0012 3456 78") # => true
|
36
|
+
|
37
|
+
The method returns true for valid ibans and false for invalid ibans. If the iban is too short or is using an unimplemented country code, the method throws an exception.
|
38
|
+
|
39
|
+
### Find bank infos
|
40
|
+
|
41
|
+
If you need to get a bank name, bank code or a bic from a german bank and you
|
42
|
+
have either a BIC or a bank code there is a bank db.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
# find a bank by BIC
|
46
|
+
bank_1 = Ibanizator.bank_db.bank_by_bic('MARKDEF1100')
|
47
|
+
bank_1.name # => 'BBk Berlin'
|
48
|
+
bank_1.bic # => 'MARKDEF1100'
|
49
|
+
bank_1.bank_code # => '10000000'
|
50
|
+
|
51
|
+
# find a bank by bank_code (de: Bankleitzahl)
|
52
|
+
bank_2 = Ibanizator.bank_db.bank_bybank_code('100 000 00')
|
53
|
+
bank_2.name # => 'BBk Berlin'
|
54
|
+
bank_2.bic # => 'MARKDEF1100'
|
55
|
+
bank_2.bank_code # => '10000000'
|
56
|
+
|
57
|
+
bank_3 = Ibanizator.bank_db.bank_bybank_code('10000000')
|
58
|
+
bank_3.name # => 'BBk Berlin'
|
59
|
+
bank_3.bic # => 'MARKDEF1100'
|
60
|
+
bank_3.bank_code # => '10000000'
|
61
|
+
|
62
|
+
bank_1 == bank_2 # => true
|
63
|
+
bank_2 == bank_3 # => true
|
64
|
+
|
65
|
+
bank_4 = Ibanizator.bank_db.bank_by_bic('OASPDE6AXXX')
|
66
|
+
bank_4 == bank_2 # => false
|
67
|
+
```
|
68
|
+
|
69
|
+
## Licence
|
70
|
+
|
71
|
+
The code is availiable under the MIT-Licence
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'equalizer'
|
2
|
+
require 'adamantium'
|
3
|
+
|
4
|
+
class Ibanizator
|
5
|
+
class Bank
|
6
|
+
include Equalizer.new(:bic, :name, :bank_code)
|
7
|
+
include Adamantium
|
8
|
+
|
9
|
+
attr_reader :bic, :name, :bank_code
|
10
|
+
|
11
|
+
def initialize(bic, name, bank_code)
|
12
|
+
@bic, @name, @bank_code = bic, name, bank_code
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class Ibanizator
|
2
|
+
class BankDb
|
3
|
+
attr_reader :known_banks
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@known_banks = []
|
7
|
+
@bic_index, @bank_code_index = {}, {}
|
8
|
+
populate_known_banks!
|
9
|
+
end
|
10
|
+
|
11
|
+
def bank_by_bic(a_bic)
|
12
|
+
@bic_index.fetch(a_bic.to_s) do
|
13
|
+
error! "No bank for bic: #{a_bic} found"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def bank_by_bank_code(a_bank_code)
|
18
|
+
@bank_code_index.fetch(sanitize_bank_code(a_bank_code)) do
|
19
|
+
error! "No bank for bank_code: #{a_bank_code} found"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def populate_known_banks!
|
25
|
+
File.open(File.expand_path("../../../db/blz.txt", __FILE__), 'r').each_line do |line|
|
26
|
+
code, _, _, _, _, name, _, bic = line.unpack 'A8A1A58A5A35A27A5A11'
|
27
|
+
next if bic.empty?
|
28
|
+
name.force_encoding('iso-8859-1').encode!('utf-8')
|
29
|
+
bank = Bank.new(bic, name, code)
|
30
|
+
@known_banks << bank
|
31
|
+
@bic_index[bank.bic] = bank
|
32
|
+
@bank_code_index[bank.bank_code] = bank
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def sanitize_bank_code(a_bank_code)
|
37
|
+
a_bank_code.to_s.gsub(/\s+/, '')
|
38
|
+
end
|
39
|
+
|
40
|
+
def error!(message)
|
41
|
+
raise BankNotFoundError, message
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/license.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 softwareinmotion GmbH
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ibanizator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christoph Stettner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: equalizer
|
@@ -94,21 +94,23 @@ dependencies:
|
|
94
94
|
- - ~>
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 4.2.10
|
97
|
-
description:
|
98
|
-
number for german accounts. It is possible to validate given international IBANS.
|
99
|
-
Calculates also the BIC and bank names for given german bank codes.
|
97
|
+
description: " \n . .\n .\n"
|
100
98
|
email: christoph.stettner@softwareinmotion.de
|
101
99
|
executables: []
|
102
100
|
extensions: []
|
103
101
|
extra_rdoc_files: []
|
104
102
|
files:
|
103
|
+
- README.md
|
105
104
|
- db/blz.txt
|
106
105
|
- lib/errors/bank_not_found_error.rb
|
107
106
|
- lib/errors/invalid_bank_code_error.rb
|
108
107
|
- lib/iban/lengths.rb
|
109
108
|
- lib/iban/validator.rb
|
110
109
|
- lib/ibanizator.rb
|
110
|
+
- lib/ibanizator/bank.rb
|
111
|
+
- lib/ibanizator/bank_db.rb
|
111
112
|
- lib/swift_bic/bank_db.rb
|
113
|
+
- license.md
|
112
114
|
homepage: https://github.com/softwareinmotion/ibanizator
|
113
115
|
licenses:
|
114
116
|
- MIT
|