class BLZ::Bank
Attributes
bic[R]
blz[R]
city[R]
name[R]
short_name[R]
zip[R]
Public Class Methods
all()
click to toggle source
Returns an array of all banks.
# File lib/blz/bank.rb, line 45 def all @banks ||= read_banks end
find_by_bic(bic, options = {})
click to toggle source
Returns an array of all Banks specified by bic
(Business Identifier Code). The following options apply:
exact:: Only return exact matches (false by default)
# File lib/blz/bank.rb, line 35 def find_by_bic(bic, options = {}) return [] if blank?(bic) exact = options.fetch(:exact, false) all.select do |bank| bank.bic == bic || (!exact && (bank.bic || '').start_with?(bic)) end end
find_by_blz(code, options = {})
click to toggle source
Returns an array of all Banks specified by code
. The following options apply:
exact:: Only return exact matches (false by default)
# File lib/blz/bank.rb, line 13 def find_by_blz(code, options = {}) return [] if blank?(code) exact = options.fetch(:exact, false) all.select do |bank| bank.blz == code || (!exact && bank.blz.start_with?(code)) end end
find_by_city(substring)
click to toggle source
Returns an array of all Banks with a substring of city
.
# File lib/blz/bank.rb, line 23 def find_by_city(substring) return [] if blank?(substring) all.select do |bank| bank.city.index(substring) end end
new(blz, name, zip, city, short_name, bic)
click to toggle source
Initializes a single Bank
record.
# File lib/blz/bank.rb, line 77 def initialize(blz, name, zip, city, short_name, bic) @blz = blz @name = name @zip = zip @city = city @bic = bic @short_name = short_name end
Private Class Methods
blank?(obj)
click to toggle source
Checks whether an object is blank (empty Array/Hash/String).
Does not rely on ActiveSupport, but prefers that implementation.
# File lib/blz/bank.rb, line 64 def blank?(obj) return true if obj.nil? return obj.blank? if obj.respond_to?(:blank?) obj = obj.strip if String === obj return obj.empty? if obj.respond_to?(:empty?) false end
read_banks()
click to toggle source
# File lib/blz/bank.rb, line 51 def read_banks banks = [] Zlib::GzipReader.open(BLZ::DATA_FILE) do |gz| CSV.new(gz, col_sep: "\t").each do |r| banks << new(r[0], r[2], r[3], r[4], r[5], r[7]) end end banks end
Public Instance Methods
to_s()
click to toggle source
Returns a nice representation of the bank.
# File lib/blz/bank.rb, line 87 def to_s [blz, name, "#{zip} #{city}", bic].compact.reject(&:empty?).join(', ') end