Class: RVGP::Pta::HLedger::Output::Register
- Defined in:
- lib/rvgp/pta/hledger.rb
Overview
An json parser, to structure the output of register queries to ledger. This object exists, as a return value, from the RVGP::Pta::HLedger#register method
Instance Attribute Summary collapse
-
#transactions ⇒ RVGP::Pta::RegisterTransaction
readonly
The transactions, and their components, that were returned by ledger.
Attributes inherited from JsonBase
Instance Method Summary collapse
-
#initialize(json, options = {}) ⇒ Register
constructor
Declare the registry, and initialize with the relevant options.
Constructor Details
#initialize(json, options = {}) ⇒ Register
Declare the registry, and initialize with the relevant options
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/rvgp/pta/hledger.rb', line 95 def initialize(json, = {}) super json, @transactions = @json.each_with_object([]) do |row, sum| row[0] ? (sum << [row]) : (sum.last << row) end @transactions.map! do |postings| date = Date.strptime postings[0][0], '%Y-%m-%d' RVGP::Pta::RegisterTransaction.new( date, postings[0][2], # Payee (postings.map do |posting| amounts, totals = [posting[3][:pamount], posting[4]].map do |pamounts| pamounts.map { |pamount| commodity_from_json pamount } end RVGP::Pta::RegisterPosting.new( posting[3][:paccount], amounts, totals, posting[3][:ptags].to_h do |pair| [pair.first, pair.last.empty? ? true : pair.last] end, 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) ) end end |
Instance Attribute Details
#transactions ⇒ RVGP::Pta::RegisterTransaction (readonly)
The transactions, and their components, that were returned by ledger.
89 90 91 |
# File 'lib/rvgp/pta/hledger.rb', line 89 def transactions @transactions end |