bankleitzahl 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.travis.yml +9 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +10 -0
- data/bankleitzahl.gemspec +24 -0
- data/lib/bankleitzahl/bank.rb +4 -0
- data/lib/bankleitzahl/fetcher.rb +61 -0
- data/lib/bankleitzahl/parser.rb +26 -0
- data/lib/bankleitzahl/version.rb +3 -0
- data/lib/bankleitzahl.rb +7 -0
- data/test/fixtures/blz_06_2013.txt +2 -0
- data/test/test_bank.rb +8 -0
- data/test/test_fetcher.rb +19 -0
- data/test/test_parser.rb +23 -0
- metadata +120 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Robert Gogolok
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/avarteqgmbh/bankleitzahl.png?branch=master)](https://travis-ci.org/avarteqgmbh/bankleitzahl)
|
2
|
+
|
3
|
+
# Bankleitzahl
|
4
|
+
|
5
|
+
- fetch Bankleitzahlendatei from bundesbank.de
|
6
|
+
- load and parse Bankleitzahlendatei
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'bankleitzahl'
|
13
|
+
|
14
|
+
## Bankleitzahldatei
|
15
|
+
|
16
|
+
Get the current Bankleitzahldatei from
|
17
|
+
http://www.bundesbank.de/Navigation/DE/Kerngeschaeftsfelder/Unbarer_Zahlungsverkehr/Bankleitzahlen/bankleitzahlen.html
|
18
|
+
|
19
|
+
There is a *Merkblatt Bankleitzahlendatei* describing the file format.
|
20
|
+
|
21
|
+
## Examples
|
22
|
+
|
23
|
+
``` ruby
|
24
|
+
content_lines = Bankleitzahl::Fetcher.current_lines # remote http request
|
25
|
+
|
26
|
+
bank = Bankleitzahl::Parser.new(content_lines).all_banks.first
|
27
|
+
bank.blz #=> "100000001"
|
28
|
+
bank.name #=> "Bundesbank"
|
29
|
+
bank.short_name #=> "BBk Berlin"
|
30
|
+
bank.zip #=> "10591"
|
31
|
+
bank.city #=> "Berlin"
|
32
|
+
bank.bic #=> "MARKDEF1100"
|
33
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bankleitzahl/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bankleitzahl"
|
8
|
+
spec.version = Bankleitzahl::VERSION
|
9
|
+
spec.authors = ["Robert Gogolok"]
|
10
|
+
spec.email = ["gogolok@gmail.com"]
|
11
|
+
spec.description = %q{Bankleitzahlen (BLZ) for Ruby}
|
12
|
+
spec.summary = %q{Bankleitzahlen fetches and parses Bankleitzahldatei from bundesbank.de}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_runtime_dependency "addressable"
|
24
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'addressable/uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
|
6
|
+
module Bankleitzahl
|
7
|
+
|
8
|
+
class Fetcher
|
9
|
+
|
10
|
+
CURRENT_URL = "http://www.bundesbank.de/Redaktion/DE/Downloads/Kerngeschaeftsfelder/Unbarer_Zahlungsverkehr/Bankleitzahlen/2013_09_08/blz_2013_06_03_txt.txt?__blob=publicationFile"
|
11
|
+
|
12
|
+
def self.current_lines(fetcher_class = HttpFile)
|
13
|
+
fetcher_class.fetch(CURRENT_URL)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
class HttpFile
|
19
|
+
|
20
|
+
attr_reader :url
|
21
|
+
|
22
|
+
def self.fetch(url)
|
23
|
+
self.new(url).get
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(url)
|
27
|
+
@url = url
|
28
|
+
end
|
29
|
+
|
30
|
+
def get
|
31
|
+
execute
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def execute(options = {})
|
37
|
+
http.read_timeout = 360 # seconds
|
38
|
+
http.set_debug_output $stderr if options[:debug]
|
39
|
+
|
40
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
41
|
+
|
42
|
+
response = http.request(request)
|
43
|
+
|
44
|
+
if response.code.to_i == 200
|
45
|
+
response.body
|
46
|
+
else
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
rescue Errno::ECONNREFUSED, Addressable::URI::InvalidURIError
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
|
53
|
+
def http
|
54
|
+
@http ||= Net::HTTP.new(uri.host, uri.port)
|
55
|
+
end
|
56
|
+
|
57
|
+
def uri
|
58
|
+
@uri ||= Addressable::URI.parse(url)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Bankleitzahl
|
2
|
+
class Parser
|
3
|
+
|
4
|
+
attr_reader :content_lines
|
5
|
+
|
6
|
+
def initialize(content_lines)
|
7
|
+
@content_lines = content_lines
|
8
|
+
end
|
9
|
+
|
10
|
+
def all_banks
|
11
|
+
@banks ||= read_all_banks
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def read_all_banks
|
17
|
+
banks = []
|
18
|
+
|
19
|
+
content_lines.each_line do |line|
|
20
|
+
banks << Bank.new(line[0..7], line[9..66].chomp, line[107..133], line[67..71], line[72..106].chomp, line[139..149].chomp)
|
21
|
+
end
|
22
|
+
|
23
|
+
banks
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/bankleitzahl.rb
ADDED
data/test/test_bank.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'bankleitzahl'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'minitest/mock'
|
4
|
+
|
5
|
+
class TestParser < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
def test_failed_fetching
|
8
|
+
fetcher_mock = MiniTest::Mock.new
|
9
|
+
fetcher_mock.expect(:fetch, nil, [Bankleitzahl::Fetcher::CURRENT_URL])
|
10
|
+
assert_equal nil, Bankleitzahl::Fetcher.current_lines(fetcher_mock)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_successful
|
14
|
+
fetcher_mock = MiniTest::Mock.new
|
15
|
+
fetcher_mock.expect(:fetch, "content", [Bankleitzahl::Fetcher::CURRENT_URL])
|
16
|
+
assert_equal "content", Bankleitzahl::Fetcher.current_lines(fetcher_mock)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/test/test_parser.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'bankleitzahl'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
class TestBank < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
def test_all_banks
|
7
|
+
assert_equal 2, Bankleitzahl::Parser.new(content_lines).all_banks.size
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_corretly_read_bank_entry
|
11
|
+
bank = Bankleitzahl::Parser.new(content_lines).all_banks.first
|
12
|
+
assert_equal "12345678", bank.blz
|
13
|
+
assert_equal "Sample Bank E", bank.name
|
14
|
+
assert_equal "BBk Berlin E", bank.short_name
|
15
|
+
assert_equal "10591", bank.zip
|
16
|
+
assert_equal "Berlin X", bank.city
|
17
|
+
assert_equal "MARKDEF1100", bank.bic
|
18
|
+
end
|
19
|
+
|
20
|
+
def content_lines
|
21
|
+
@content_lines ||= File.read(File.join(File.dirname(__FILE__), 'fixtures', 'blz_06_2013.txt'))
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bankleitzahl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Robert Gogolok
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: addressable
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Bankleitzahlen (BLZ) for Ruby
|
63
|
+
email:
|
64
|
+
- gogolok@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .travis.yml
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- bankleitzahl.gemspec
|
76
|
+
- lib/bankleitzahl.rb
|
77
|
+
- lib/bankleitzahl/bank.rb
|
78
|
+
- lib/bankleitzahl/fetcher.rb
|
79
|
+
- lib/bankleitzahl/parser.rb
|
80
|
+
- lib/bankleitzahl/version.rb
|
81
|
+
- test/fixtures/blz_06_2013.txt
|
82
|
+
- test/test_bank.rb
|
83
|
+
- test/test_fetcher.rb
|
84
|
+
- test/test_parser.rb
|
85
|
+
homepage: ''
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
hash: 4416177468560395139
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
hash: 4416177468560395139
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 1.8.25
|
113
|
+
signing_key:
|
114
|
+
specification_version: 3
|
115
|
+
summary: Bankleitzahlen fetches and parses Bankleitzahldatei from bundesbank.de
|
116
|
+
test_files:
|
117
|
+
- test/fixtures/blz_06_2013.txt
|
118
|
+
- test/test_bank.rb
|
119
|
+
- test/test_fetcher.rb
|
120
|
+
- test/test_parser.rb
|