Class: AqBanking::Parsed::Account

Inherits:
Object
  • Object
show all
Extended by:
DefineField
Defined in:
lib/aq_banking/parsed/account.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DefineField

define_field

Constructor Details

#initialize(tree) ⇒ Account

Returns a new instance of Account.

Raises:

  • (ArgumentError)


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

#treeObject (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_balanceObject

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_balanceObject

See Also:

  • booked_balane


34
35
36
# File 'lib/aq_banking/parsed/account.rb', line 34

def noted_balance
  first_status_with :noted_balance
end

#statusesObject



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_hObject



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_jsonObject



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_rawObject



58
59
60
# File 'lib/aq_banking/parsed/account.rb', line 58

def to_raw
  tree.text_value
end

#transactionsObject



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