blz 0.1.0
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.
- data/CHANGELOG.md +4 -0
- data/Gemfile +8 -0
- data/LICENSE +21 -0
- data/README.md +59 -0
- data/Rakefile +23 -0
- data/bin/blz +32 -0
- data/blz.gemspec +36 -0
- data/data/blz.tsv +19514 -0
- data/data/blz_2012_06_04_xls.xlsx +0 -0
- data/lib/blz.rb +10 -0
- data/lib/blz/bank.rb +85 -0
- data/test/test_bank.rb +44 -0
- metadata +117 -0
Binary file
|
data/lib/blz.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Copyright (C) 2012 Oliver Eilhard
|
2
|
+
#
|
3
|
+
# This library is freely distributable under the terms of
|
4
|
+
# an MIT-style license.
|
5
|
+
# See COPYING or http://www.opensource.org/licenses/mit-license.php.
|
6
|
+
#
|
7
|
+
# Provides information about "Bankleitzahlen" (BLZ),
|
8
|
+
# a bank identifier code system used by German and Austrian banks.
|
9
|
+
|
10
|
+
require 'blz/bank'
|
data/lib/blz/bank.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module BLZ
|
4
|
+
# Represents a bank with a BLZ, a BIC, a name etc.
|
5
|
+
class Bank
|
6
|
+
# BLZ = a bank idenfier code widely used in DE and AT
|
7
|
+
attr_reader :blz
|
8
|
+
# Name of the bank
|
9
|
+
attr_reader :name
|
10
|
+
# Postal code
|
11
|
+
attr_reader :zip
|
12
|
+
# City
|
13
|
+
attr_reader :city
|
14
|
+
# Short name = short description of the bank
|
15
|
+
attr_reader :short_name
|
16
|
+
# BIC = bank identifier code (ISO 9362)
|
17
|
+
attr_reader :bic
|
18
|
+
|
19
|
+
# Initializes a single Bank record.
|
20
|
+
def initialize(blz, name, zip, city, short_name, bic)
|
21
|
+
@blz = blz
|
22
|
+
@name = name
|
23
|
+
@zip = zip
|
24
|
+
@city = city
|
25
|
+
@short_name = short_name
|
26
|
+
@bic = bic
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns an array of all Banks specified by +code+.
|
30
|
+
# The following options apply:
|
31
|
+
#
|
32
|
+
# exact:: Only return exact matches (false by default)
|
33
|
+
#
|
34
|
+
def self.find_by_blz(code, options = nil)
|
35
|
+
options ||= {}
|
36
|
+
exact = options.fetch(:exact, false)
|
37
|
+
|
38
|
+
self.all.inject([]) do |results, bank|
|
39
|
+
if bank.blz == code || (!exact && bank.blz.start_with?(code))
|
40
|
+
results << bank
|
41
|
+
end
|
42
|
+
results
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Returns an array of all Banks with a substring of +city+.
|
47
|
+
def self.find_by_city(substring)
|
48
|
+
self.all.inject([]) do |results, bank|
|
49
|
+
results << bank if bank.city.index(substring)
|
50
|
+
results
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns an array of all banks.
|
55
|
+
def self.all
|
56
|
+
# TODO is this the right way to do it?
|
57
|
+
Thread.current[:'BLZ::Bank.all'] ||= read_banks
|
58
|
+
end
|
59
|
+
|
60
|
+
# Returns a nice representation of the bank.
|
61
|
+
def to_s
|
62
|
+
[blz, name, "#{zip} #{city}", bic].reject { |s| s.empty? }.join ", "
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def self.read_banks
|
68
|
+
banks = []
|
69
|
+
filename = File.join(File.dirname(__FILE__), '..', '..', 'data', 'blz.tsv')
|
70
|
+
File.foreach(filename) do |line|
|
71
|
+
columns = line.split /\t/
|
72
|
+
blz = columns[0].strip
|
73
|
+
name = columns[2].strip
|
74
|
+
zip = columns[3].strip
|
75
|
+
city = columns[4].strip
|
76
|
+
short_name = columns[5].strip
|
77
|
+
bic = columns[7].strip
|
78
|
+
banks << Bank.new(blz, name, zip, city, short_name, bic)
|
79
|
+
end
|
80
|
+
banks
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
data/test/test_bank.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'blz'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class TestBank < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_all_banks
|
9
|
+
assert !BLZ::Bank.all.nil?
|
10
|
+
assert sskm = BLZ::Bank.all.find { |b| b.blz == "70150000" }
|
11
|
+
assert_equal "Stadtsparkasse München", sskm.name
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_search_by_exact_match
|
15
|
+
assert results = BLZ::Bank.find_by_blz("70150000", :exact => true)
|
16
|
+
assert_equal 1, results.size
|
17
|
+
assert_equal "70150000", results[0].blz
|
18
|
+
assert_equal "Stadtsparkasse München", results[0].name
|
19
|
+
assert_equal "St Spk München", results[0].short_name
|
20
|
+
assert_equal "80791", results[0].zip
|
21
|
+
assert_equal "München", results[0].city
|
22
|
+
assert_equal "SSKMDEMMXXX", results[0].bic
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_search_by_prefix
|
26
|
+
assert results = BLZ::Bank.find_by_blz("7106")
|
27
|
+
assert results.size > 1
|
28
|
+
#assert_equal "Stadtsparkasse München", results[0].bezeichnung
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_search_by_city
|
32
|
+
assert results = BLZ::Bank.find_by_city("München")
|
33
|
+
assert results.size > 1
|
34
|
+
assert results.find { |b| b.blz == "70150000" }
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_to_s
|
38
|
+
assert results = BLZ::Bank.find_by_blz("70150000", :exact_only => true)
|
39
|
+
assert_equal 1, results.size
|
40
|
+
assert_equal "70150000, Stadtsparkasse München, 80791 München, SSKMDEMMXXX", results[0].to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Oliver Eilhard
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-27 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.2'
|
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.2'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rdoc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.5'
|
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: '2.5'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0.9'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
description: ! 'BLZ (Bankleitzahlen) is a small library for looking up
|
63
|
+
|
64
|
+
the widely used bank identifier code system in Germany
|
65
|
+
|
66
|
+
and Austria.
|
67
|
+
|
68
|
+
|
69
|
+
http://github.com/olivere/blz
|
70
|
+
|
71
|
+
'
|
72
|
+
email: oliver.eilhard@gmail.com
|
73
|
+
executables:
|
74
|
+
- blz
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files:
|
77
|
+
- CHANGELOG.md
|
78
|
+
- LICENSE
|
79
|
+
- README.md
|
80
|
+
files:
|
81
|
+
- CHANGELOG.md
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- bin/blz
|
87
|
+
- blz.gemspec
|
88
|
+
- data/blz.tsv
|
89
|
+
- data/blz_2012_06_04_xls.xlsx
|
90
|
+
- lib/blz.rb
|
91
|
+
- lib/blz/bank.rb
|
92
|
+
- test/test_bank.rb
|
93
|
+
homepage: http://github.com/olivere/blz
|
94
|
+
licenses: []
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.8.23
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: BLZ (Bankleitzahlen) for Ruby
|
117
|
+
test_files: []
|