Class: Gnucash::Transaction
- Inherits:
-
Object
- Object
- Gnucash::Transaction
- Includes:
- Support::LightInspect
- Defined in:
- lib/gnucash/transaction.rb
Overview
Represent a GnuCash transaction.
Transactions have multiple splits with individual values. Splits are created as AccountTransaction objects which are associated with an individual account.
Instance Attribute Summary collapse
-
#date ⇒ Date
readonly
The date of the transaction.
-
#description ⇒ String
readonly
The description of the transaction.
-
#id ⇒ String
readonly
The GUID of the transaction.
-
#splits ⇒ Array<Hash>
readonly
Hashes with keys
:account
and:value
.
Instance Method Summary collapse
-
#attributes ⇒ Array<Symbol>
Attributes available for inspection.
-
#initialize(book, node) ⇒ Transaction
constructor
Create a new Transaction object.
Methods included from Support::LightInspect
Constructor Details
#initialize(book, node) ⇒ Transaction
Create a new Transaction object.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# 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 |
Instance Attribute Details
#date ⇒ Date (readonly)
Returns The date of the transaction.
13 14 15 |
# File 'lib/gnucash/transaction.rb', line 13 def date @date end |
#description ⇒ String (readonly)
Returns The description of the transaction.
19 20 21 |
# File 'lib/gnucash/transaction.rb', line 19 def description @description end |
#id ⇒ String (readonly)
Returns The GUID of the transaction.
16 17 18 |
# File 'lib/gnucash/transaction.rb', line 16 def id @id end |
#splits ⇒ Array<Hash> (readonly)
Returns Hashes with keys :account
and :value
.
22 23 24 |
# File 'lib/gnucash/transaction.rb', line 22 def splits @splits end |
Instance Method Details
#attributes ⇒ Array<Symbol>
Attributes available for inspection
56 57 58 |
# File 'lib/gnucash/transaction.rb', line 56 def attributes %i[id date description splits] end |