class Gnucash::Transaction
Represent a GnuCash transaction.
Transactions have multiple splits with individual values. Splits are created as AccountTransaction
objects which are associated with an individual account.
Attributes
date[R]
@return [Date] The date of the transaction.
description[R]
@return [String] The description of the transaction.
id[R]
@return [String] The GUID of the transaction.
splits[R]
@return [Array<Hash>] Hashes with keys :account
and :value
.
Public Class Methods
new(book, node)
click to toggle source
Create a new Transaction
object.
@param book [Book] The {Gnucash::Book} containing the transaction. @param node [Nokogiri::XML::Node] Nokogiri XML node.
# File lib/gnucash/transaction.rb, line 28 def initialize(book, node) @book = book @node = node @id = node.xpath('trn:id').text @date = Date.parse(node.xpath('trn:date-posted/ts:date').text.split(' ').first) @description = node.xpath('trn:description').text @splits = node.xpath('trn:splits/trn:split').map do |split_node| # Note: split:value represents the split value in the transaction's # currency while split:quantity represents it in the currency # associated with the account associated with this split. value = Value.new(split_node.xpath('split:quantity').text) account_id = split_node.xpath('split:account').text account = @book.find_account_by_id(account_id) unless account raise "Could not find account with ID #{account_id} for transaction #{@id}" end account.add_transaction(AccountTransaction.new(self, value)) { account: account, value: value, } end end
Public Instance Methods
attributes()
click to toggle source
Attributes available for inspection
@return [Array<Symbol>] Attributes used to build the inspection string @see Gnucash::Support::LightInspect
# File lib/gnucash/transaction.rb, line 56 def attributes %i[id date description splits] end