Class: RVGP::Pta::Ledger::Output::Register
- Defined in:
- lib/rvgp/pta/ledger.rb
Overview
An xml parser, to structure the output of register queries to ledger. This object exists, as a return value, from the RVGP::Pta::Ledger#register method
Instance Attribute Summary collapse
-
#transactions ⇒ RVGP::Pta::RegisterTransaction
readonly
The transactions, and their components, that were returned by ledger.
Attributes inherited from XmlBase
Instance Method Summary collapse
-
#initialize(xml, options = {}) ⇒ Register
constructor
Declare the registry, and initialize with the relevant options.
Constructor Details
#initialize(xml, options = {}) ⇒ Register
Declare the registry, and initialize with the relevant options
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/rvgp/pta/ledger.rb', line 124 def initialize(xml, = {}) super xml, @transactions = doc.xpath('//transactions/transaction').collect do |xt| date = Date.strptime(xt.at('date').content, '%Y/%m/%d') RVGP::Pta::RegisterTransaction.new( date, xt.at('payee').content, xt.xpath('postings/posting').collect do |xp| amounts, totals = *%w[post-amount total].collect do |attr| xp.at(attr).search('amount').collect do |xa| RVGP::Journal::Commodity.from_symbol_and_amount( xa.at('commodity/symbol')&.content, xa.at('quantity').content ) end end if [:empty] == false amounts.reject! { |amnt| amnt.quantity.zero? } totals.reject! { |amnt| amnt.quantity.zero? } next if [amounts, totals].all?(&:empty?) end account = xp.at('account/name').content # This phenomenon of '<None>' and '<total>', seems to only happen # when the :empty parameter is passed. if [:translate_meta_accounts] case account when '<None>' then account = nil when '<Total>' then account = :total end end RVGP::Pta::RegisterPosting.new( account, amounts, totals, xp.search('metadata/value').to_h { |xvalue| [xvalue['key'], xvalue.content] }, pricer: pricer, # This sets our date to the end -of the month, if this is a # monthly query price_date: [:monthly] ? Date.new(date.year, date.month, -1) : date ) end.compact ) end end |
Instance Attribute Details
#transactions ⇒ RVGP::Pta::RegisterTransaction (readonly)
The transactions, and their components, that were returned by ledger.
118 119 120 |
# File 'lib/rvgp/pta/ledger.rb', line 118 def transactions @transactions end |