Class: Figo::Base
- Inherits:
-
Object
- Object
- Figo::Base
- Defined in:
- lib/base.rb
Overview
Abstract base class for model objects.
Direct Known Subclasses
Account, AccountBalance, Bank, Notification, Payment, Security, StandingOrder, SynchronizationStatus, TaskState, TaskToken, Transaction, User
Class Method Summary collapse
Instance Method Summary collapse
-
#dump ⇒ Object
Dump committable attributes to a hash.
-
#initialize(session, hash) ⇒ Base
constructor
Instantiate model object from hash.
Constructor Details
#initialize(session, hash) ⇒ Base
Instantiate model object from hash.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/base.rb', line 20 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_attributes ⇒ Object
12 13 14 |
# File 'lib/base.rb', line 12 def self.dump_attributes @dump_attributes end |
Instance Method Details
#dump ⇒ Object
Dump committable attributes to a hash
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/base.rb', line 44 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 |