Class: RVGP::Pta::Ledger::Output::Balance
- Defined in:
- lib/rvgp/pta/ledger.rb
Overview
An xml parser, to structure the output of balance queries to ledger. This object exists, as a return value, from the RVGP::Pta::Ledger#balance method
Instance Attribute Summary collapse
-
#accounts ⇒ RVGP::Pta::BalanceAccount
readonly
The accounts, and their components, that were returned by ledger.
Attributes inherited from XmlBase
Instance Method Summary collapse
-
#initialize(xml, options = {}) ⇒ Balance
constructor
Declare the registry, and initialize with the relevant options.
Constructor Details
#initialize(xml, options = {}) ⇒ Balance
Declare the registry, and initialize with the relevant options
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rvgp/pta/ledger.rb', line 81 def initialize(xml, = {}) super xml, # NOTE: Our output matches the --flat output, of ledger. We mostly do this # because hledger defaults to the same output. It might cause some # expectations to fail though, if you're comparing our balance return, # to the cli output of balance # # Bear in mind that this query is slightly odd, in that account is nested # So, I stipulate that we are at the end of a nest "not account" and # have children "*" xaccounts = doc.xpath('//accounts//account[not(account[*]) and *]') if xaccounts @accounts = xaccounts.collect do |xaccount| fullname = xaccount.at('fullname')&.content next unless fullname RVGP::Pta::BalanceAccount.new( fullname, xaccount.xpath('account-amount/amount|account-amount/*/amount').collect do |amount| commodity = RVGP::Journal::Commodity.from_symbol_and_amount( amount.at('symbol').content, amount.at('quantity').content ) commodity if commodity.quantity != 0 end.compact ) end.compact end end |
Instance Attribute Details
#accounts ⇒ RVGP::Pta::BalanceAccount (readonly)
The accounts, and their components, that were returned by ledger.
75 76 77 |
# File 'lib/rvgp/pta/ledger.rb', line 75 def accounts @accounts end |