Class: JpBank::Bank

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

Defined Under Namespace

Classes: NotFound

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Bank

Returns a new instance of Bank.


32
33
34
# File 'lib/jp_bank/bank.rb', line 32

def initialize(data)
  @data = data
end

Class Method Details

.codesObject


5
6
7
8
# File 'lib/jp_bank/bank.rb', line 5

def self.codes
  self.load_banks unless @bank_codes
  @bank_codes.keys
end

.fetch_bank_from_code(code) ⇒ Object


10
11
12
13
14
# File 'lib/jp_bank/bank.rb', line 10

def self.fetch_bank_from_code(code)
  self.load_banks unless @bank_codes
  code = '%04d' % code if code.is_a?(Integer)
  @bank_codes[code]
end

.fetch_bank_from_name(name) ⇒ Object


16
17
18
19
# File 'lib/jp_bank/bank.rb', line 16

def self.fetch_bank_from_name(name)
  self.load_banks unless @bank_names
  @bank_names[name]
end

.find(code_or_name) ⇒ Object


21
22
23
24
# File 'lib/jp_bank/bank.rb', line 21

def self.find(code_or_name)
  self.fetch_bank_from_code(code_or_name) or 
    self.fetch_bank_from_name(code_or_name)
end

.find!(code_or_name) ⇒ Object

Raises:


26
27
28
29
30
# File 'lib/jp_bank/bank.rb', line 26

def self.find!(code_or_name)
  bank = find(code_or_name)
  raise NotFound if bank.nil?
  bank
end

Instance Method Details

#codeObject


36
37
38
# File 'lib/jp_bank/bank.rb', line 36

def code
  @data['code']
end

#nameObject


40
41
42
# File 'lib/jp_bank/bank.rb', line 40

def name
  @data['name']
end