Class: AqBanking::Parsed::Account
- Inherits:
-
Object
- Object
- AqBanking::Parsed::Account
- Extended by:
- DefineField
- Defined in:
- lib/aq_banking/parsed/account.rb
Instance Attribute Summary collapse
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Instance Method Summary collapse
-
#booked_balance ⇒ Object
some banks return multiple statuses containing multiple booked_balance and noted balance.
-
#initialize(tree) ⇒ Account
constructor
A new instance of Account.
- #noted_balance ⇒ Object
- #statuses ⇒ Object
- #to_h ⇒ Object
- #to_json ⇒ Object
- #to_raw ⇒ Object
- #transactions ⇒ Object
Methods included from DefineField
Constructor Details
#initialize(tree) ⇒ Account
Returns a new instance of Account.
14 15 16 17 18 19 |
# File 'lib/aq_banking/parsed/account.rb', line 14 def initialize tree raise ArgumentError.new('tree must be an AccountInfoList::Block') unless tree.is_a? AccountInfoList::Block raise ArgumentError.new('block_name must be accountInfo') unless tree.name == 'accountInfo' @tree = tree end |
Instance Attribute Details
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
7 8 9 |
# File 'lib/aq_banking/parsed/account.rb', line 7 def tree @tree end |
Instance Method Details
#booked_balance ⇒ Object
some banks return multiple statuses containing multiple booked_balance and noted balance. When called on the acccount, it uses the last status (ordered by status.time) that contains a booked_balance / noted_balance
29 30 31 |
# File 'lib/aq_banking/parsed/account.rb', line 29 def booked_balance first_status_with :booked_balance end |
#noted_balance ⇒ Object
34 35 36 |
# File 'lib/aq_banking/parsed/account.rb', line 34 def noted_balance first_status_with :noted_balance end |
#statuses ⇒ Object
21 22 23 24 25 |
# File 'lib/aq_banking/parsed/account.rb', line 21 def statuses raise 'tree must be set' if tree.nil? tree.query('statusList status').map { |block| Status.new(block) }.sort_by(&:time).reverse end |
#to_h ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/aq_banking/parsed/account.rb', line 44 def to_h result = %i(iban bic owner currency bank_code bank_name booked_balance noted_balance number name type id).inject({}) do |result, field| result[field] = send(field) result end result[:transactions] = transactions.map &:to_h result end |
#to_json ⇒ Object
54 55 56 |
# File 'lib/aq_banking/parsed/account.rb', line 54 def to_json JSON.pretty_generate(to_h.to_camelback_keys) end |
#to_raw ⇒ Object
58 59 60 |
# File 'lib/aq_banking/parsed/account.rb', line 58 def to_raw tree.text_value end |
#transactions ⇒ Object
38 39 40 41 42 |
# File 'lib/aq_banking/parsed/account.rb', line 38 def transactions tree.get_blocks('transactionList transaction').map do |block| Transaction.new(block) end end |