Class: RVGP::Pta::Ledger::Output::XmlBase

Inherits:
Object
  • Object
show all
Defined in:
lib/rvgp/pta/ledger.rb

Overview

This is a base class from which RVGP::Pta::Ledger’s outputs inherit. It mostly just provides helpers for dealing with the xml output that ledger produces.

Direct Known Subclasses

Balance, Register

Defined Under Namespace

Classes: Commodity

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml, options) ⇒ XmlBase

Declare the class, and initialize with the relevant options

Parameters:

  • xml (String)

    The xml document this object is composed from

  • options (Hash)

    Additional options

Options Hash (options):



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rvgp/pta/ledger.rb', line 50

def initialize(xml, options)
  @doc = Nokogiri::XML xml, &:noblanks
  @pricer = options[:pricer] || RVGP::Journal::Pricer.new

  @commodities = doc.search('//commodities//commodity[annotation]').collect do |xcommodity|
    next unless ['symbol', 'date', 'price', 'price/commodity/symbol',
                 'price/quantity'].all? { |path| xcommodity.at(path) }

    symbol = xcommodity.at('symbol').content
    date = Date.strptime(xcommodity.at('date').content, '%Y/%m/%d')
    commodity = RVGP::Journal::Commodity.from_symbol_and_amount(
      xcommodity.at('price/commodity/symbol').content,
      xcommodity.at('price/quantity').content
    )

    @pricer.add date.to_time, symbol, commodity
    Commodity.new symbol, date, commodity
  end
end

Instance Attribute Details

#commoditiesArray<RVGP::Pta::Ledger::Output::XmlBase::Commodity> (readonly)

The exchange rates that were reportedly encountered, in the output of ledger.

Returns:



31
32
33
# File 'lib/rvgp/pta/ledger.rb', line 31

def commodities
  @commodities
end

#docNokogiri::XML (readonly)

The document that was produced by ledger, to construct this object

Returns:

  • (Nokogiri::XML)

    the current value of doc



31
32
33
# File 'lib/rvgp/pta/ledger.rb', line 31

def doc
  @doc
end

#pricerRVGP::Journal::Pricer (readonly)

A price exchanger, to use for any currency exchange lookups

Returns:



31
32
33
# File 'lib/rvgp/pta/ledger.rb', line 31

def pricer
  @pricer
end