Class: RVGP::Pta::Ledger::Output::XmlBase
- Inherits:
-
Object
- Object
- RVGP::Pta::Ledger::Output::XmlBase
- 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.
Defined Under Namespace
Classes: Commodity
Instance Attribute Summary collapse
-
#commodities ⇒ Array<RVGP::Pta::Ledger::Output::XmlBase::Commodity>
readonly
The exchange rates that were reportedly encountered, in the output of ledger.
-
#doc ⇒ Nokogiri::XML
readonly
The document that was produced by ledger, to construct this object.
-
#pricer ⇒ RVGP::Journal::Pricer
readonly
A price exchanger, to use for any currency exchange lookups.
Instance Method Summary collapse
-
#initialize(xml, options) ⇒ XmlBase
constructor
Declare the class, and initialize with the relevant options.
Constructor Details
#initialize(xml, options) ⇒ XmlBase
Declare the class, and initialize with the relevant 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, ) @doc = Nokogiri::XML xml, &:noblanks @pricer = [: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
#commodities ⇒ Array<RVGP::Pta::Ledger::Output::XmlBase::Commodity> (readonly)
The exchange rates that were reportedly encountered, in the output of ledger.
31 32 33 |
# File 'lib/rvgp/pta/ledger.rb', line 31 def commodities @commodities end |
#doc ⇒ Nokogiri::XML (readonly)
The document that was produced by ledger, to construct this object
31 32 33 |
# File 'lib/rvgp/pta/ledger.rb', line 31 def doc @doc end |
#pricer ⇒ RVGP::Journal::Pricer (readonly)
A price exchanger, to use for any currency exchange lookups
31 32 33 |
# File 'lib/rvgp/pta/ledger.rb', line 31 def pricer @pricer end |