bankleitzahl 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+
7
+ notifications:
8
+ email:
9
+ - rgogolok@avarteq.de
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
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,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.test_files = FileList['test/test*.rb']
7
+ end
8
+
9
+ desc "Run all tests"
10
+ task :default => [:test]
@@ -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,4 @@
1
+ module Bankleitzahl
2
+ class Bank < Struct.new(:blz, :name, :short_name, :zip, :city, :bic)
3
+ end
4
+ 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
@@ -0,0 +1,3 @@
1
+ module Bankleitzahl
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,7 @@
1
+ require "bankleitzahl/bank"
2
+ require "bankleitzahl/fetcher"
3
+ require "bankleitzahl/parser"
4
+ require "bankleitzahl/version"
5
+
6
+ module Bankleitzahl
7
+ end
@@ -0,0 +1,2 @@
1
+ 123456789Sample Bank E10591Berlin XBBk Berlin E20100MARKDEF110009011380U000000000
2
+ 100000000Bundesbank 10591Berlin BBk Berlin 20100MARKDEF110009011380U000000000
data/test/test_bank.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'bankleitzahl'
2
+ require 'minitest/autorun'
3
+
4
+ class TestBank < MiniTest::Unit::TestCase
5
+ def test_presence
6
+ assert_equal "BLZ", Bankleitzahl::Bank.new("BLZ").blz
7
+ end
8
+ end
@@ -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
@@ -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