Class: RVGP::Pta::Ledger::Output::Register

Inherits:
XmlBase
  • Object
show all
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

Attributes inherited from XmlBase

#commodities, #doc, #pricer

Instance Method Summary collapse

Constructor Details

#initialize(xml, options = {}) ⇒ Register

Declare the registry, and initialize with the relevant options

Parameters:



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, options = {})
  super xml, options

  @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 options[:empty] == false
          amounts.reject! { |amnt| amnt.quantity.zero? }
          totals.reject! { |amnt| amnt.quantity.zero? }

          next if [amounts, totals].all?(&:empty?)
        end

         = xp.at('account/name').content

        # This phenomenon of '<None>' and '<total>', seems to only happen
        # when the :empty parameter is passed.
        if options[:translate_meta_accounts]
          case 
          when '<None>' then  = nil
          when '<Total>' then  = :total
          end
        end

        RVGP::Pta::RegisterPosting.new(
          ,
          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: options[:monthly] ? Date.new(date.year, date.month, -1) : date
        )
      end.compact
    )
  end
end

Instance Attribute Details

#transactionsRVGP::Pta::RegisterTransaction (readonly)

The transactions, and their components, that were returned by ledger.

Returns:



118
119
120
# File 'lib/rvgp/pta/ledger.rb', line 118

def transactions
  @transactions
end