Class: Figo::Base

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

Overview

Abstract base class for model objects.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session, hash) ⇒ Base

Instantiate model object from hash.

Parameters:

  • session (Session)

    figo ‘Session` object

  • hash (Hash)

    use keys of this hash for model object creation



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/models.rb', line 43

def initialize(session, hash)
  @session = session

  hash.each do |key, value|
    key = key.to_s if key.is_a? Symbol
    next unless respond_to? "#{key}="
    next if value.nil?

    if key == "status" and value.is_a? Hash
      value = SynchronizationStatus.new(session, value)
    elsif key == "balance" and value.is_a? Hash
      value = AccountBalance.new(session, value)
    elsif key == "amount" or key == "balance" or key == "credit_line" or key == "monthly_spending_limit"
      value = Flt::DecNum(value.to_s)
    elsif key.end_with?("_date")
      value = DateTime.iso8601(value)
    elsif key.end_with?("_timestamp")
      value = DateTime.iso8601(value)
    end
    send("#{key}=", value)
  end
end

Class Method Details

.dump_attributesObject



35
36
37
# File 'lib/models.rb', line 35

def self.dump_attributes
  @dump_attributes
end

Instance Method Details

#dumpObject

Dump committable attributes to a hash



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/models.rb', line 67

def dump
  result = {}
  self.class.dump_attributes.each do |attribute|
    value = send attribute
    next if value.nil?
    value = value.to_f if value.is_a? Flt::DecNum

    result[attribute] = value
  end
  return result
end