Class: BLZ::Bank

Inherits:
Object
  • Object
show all
Defined in:
lib/blz/bank.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blz, name, zip, city, short_name, bic) ⇒ Bank

Initializes a single Bank record.



77
78
79
80
81
82
83
84
# 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

Instance Attribute Details

#bicObject (readonly)

Returns the value of attribute bic.



74
75
76
# File 'lib/blz/bank.rb', line 74

def bic
  @bic
end

#blzObject (readonly)

Returns the value of attribute blz.



74
75
76
# File 'lib/blz/bank.rb', line 74

def blz
  @blz
end

#cityObject (readonly)

Returns the value of attribute city.



74
75
76
# File 'lib/blz/bank.rb', line 74

def city
  @city
end

#nameObject (readonly)

Returns the value of attribute name.



74
75
76
# File 'lib/blz/bank.rb', line 74

def name
  @name
end

#short_nameObject (readonly)

Returns the value of attribute short_name.



74
75
76
# File 'lib/blz/bank.rb', line 74

def short_name
  @short_name
end

#zipObject (readonly)

Returns the value of attribute zip.



74
75
76
# File 'lib/blz/bank.rb', line 74

def zip
  @zip
end

Class Method Details

.allObject

Returns an array of all banks.



45
46
47
# File 'lib/blz/bank.rb', line 45

def all
  @banks ||= read_banks
end

.find_by_bic(bic, options = {}) ⇒ Object

Returns an array of all Banks specified by bic (Business Identifier Code). The following options apply:

exact:: Only return exact matches (false by default)


35
36
37
38
39
40
41
42
# 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 = {}) ⇒ Object

Returns an array of all Banks specified by code. The following options apply:

exact:: Only return exact matches (false by default)


13
14
15
16
17
18
19
20
# 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) ⇒ Object

Returns an array of all Banks with a substring of city.



23
24
25
26
27
28
29
# 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

Instance Method Details

#to_sObject

Returns a nice representation of the bank.



87
88
89
# File 'lib/blz/bank.rb', line 87

def to_s
  [blz, name, "#{zip} #{city}", bic].compact.reject(&:empty?).join(', ')
end