Class: Codabel::Model::Account

Inherits:
Codabel::Model show all
Defined in:
lib/codabel/model/account.rb

Constant Summary collapse

BELGIAN_BBAN =
:belgian_bban
FOREIGN_BBAN =
:foreign_bban
BELGIAN_IBAN =
:belgian_iban
FOREIGN_IBAN =
:foreign_iban

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.dress(value) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/codabel/model/account.rb', line 9

def self.dress(value)
  case value
  when Account then value
  when String  then new(number: value)
  when Hash    then new(value)
  else
    raise ArgumentError, "Unable to dress `#{value}` as an Account"
  end
end

Instance Method Details

#currencyObject



19
20
21
# File 'lib/codabel/model/account.rb', line 19

def currency
  @currency ||= (super || 'EUR').to_s.gsub(/\s/, '')
end

#infer_structureObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/codabel/model/account.rb', line 31

def infer_structure
  case number.to_s.strip
  when /^BE\d{14}$/
    BELGIAN_IBAN
  when /^[A-Z]{2}\d{2}\d{12,30}/
    FOREIGN_IBAN
  when /^\d{12}$/
    BELGIAN_BBAN
  else
    FOREIGN_BBAN
  end
end

#numberObject



23
24
25
# File 'lib/codabel/model/account.rb', line 23

def number
  @number ||= super.to_s.gsub(/\s/, '')
end

#structureObject



27
28
29
# File 'lib/codabel/model/account.rb', line 27

def structure
  @structure ||= super || infer_structure
end