blz 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/README.md +4 -0
- data/blz.gemspec +1 -1
- data/lib/blz/bank.rb +43 -68
- metadata +2 -2
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -52,6 +52,10 @@ from the German Bundesbank
|
|
52
52
|
[here](http://www.bundesbank.de/Redaktion/DE/Standardartikel/Kerngeschaeftsfelder/Unbarer_Zahlungsverkehr/bankleitzahlen_download.html).
|
53
53
|
Now go and build your own BLZ gem ;-)
|
54
54
|
|
55
|
+
## Contributors
|
56
|
+
|
57
|
+
* [max-power](https://github.com/max-power)
|
58
|
+
|
55
59
|
## License
|
56
60
|
|
57
61
|
Released under the MIT License. See the LICENSE file for further
|
data/blz.gemspec
CHANGED
data/lib/blz/bank.rb
CHANGED
@@ -1,85 +1,60 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
require 'csv'
|
2
3
|
|
3
4
|
module BLZ
|
4
|
-
# Represents a bank with a BLZ, a BIC, a name etc.
|
5
5
|
class Bank
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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)
|
6
|
+
# Represents a bank with a BLZ, a BIC, a name etc.
|
7
|
+
class << self
|
8
|
+
# Returns an array of all Banks specified by +code+.
|
9
|
+
# The following options apply:
|
10
|
+
# exact:: Only return exact matches (false by default)
|
11
|
+
#
|
12
|
+
def find_by_blz(code, options = {})
|
13
|
+
exact = options.fetch(:exact, false)
|
14
|
+
all.select do |bank|
|
15
|
+
bank.blz == code || (!exact && bank.blz.start_with?(code))
|
16
|
+
end
|
17
|
+
end
|
37
18
|
|
38
|
-
|
39
|
-
|
40
|
-
|
19
|
+
# Returns an array of all Banks with a substring of +city+.
|
20
|
+
def find_by_city(substring)
|
21
|
+
all.select do |bank|
|
22
|
+
bank.city.index(substring)
|
41
23
|
end
|
42
|
-
results
|
43
24
|
end
|
44
|
-
end
|
45
25
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
26
|
+
# Returns an array of all banks.
|
27
|
+
def all
|
28
|
+
@banks ||= read_banks
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def read_banks
|
34
|
+
banks = []
|
35
|
+
filename = File.expand_path('data/blz.tsv')
|
36
|
+
CSV.foreach(filename, col_sep: "\t") do |r|
|
37
|
+
banks << new(r[0], r[2], r[3], r[4], r[5], r[7])
|
38
|
+
end
|
39
|
+
banks
|
51
40
|
end
|
52
41
|
end
|
42
|
+
|
43
|
+
attr_reader :blz, :name, :zip, :city, :short_name, :bic
|
53
44
|
|
54
|
-
#
|
55
|
-
def
|
56
|
-
|
57
|
-
|
45
|
+
# Initializes a single Bank record.
|
46
|
+
def initialize(blz, name, zip, city, short_name, bic)
|
47
|
+
@blz = blz
|
48
|
+
@name = name
|
49
|
+
@zip = zip
|
50
|
+
@city = city
|
51
|
+
@bic = bic
|
52
|
+
@short_name = short_name
|
58
53
|
end
|
59
54
|
|
60
55
|
# Returns a nice representation of the bank.
|
61
56
|
def to_s
|
62
|
-
[blz, name, "#{zip} #{city}", bic].reject
|
57
|
+
[blz, name, "#{zip} #{city}", bic].compact.reject(&:empty?).join(', ')
|
63
58
|
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
59
|
end
|
84
|
-
end
|
85
|
-
|
60
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|