Class: Gnucash::Book
- Inherits:
-
Object
- Object
- Gnucash::Book
- Includes:
- Support::LightInspect
- Defined in:
- lib/gnucash/book.rb
Overview
Represent a GnuCash Book.
Instance Attribute Summary collapse
-
#accounts ⇒ Array<Account>
readonly
Accounts in the book.
-
#customers ⇒ Array<Account>
readonly
Customers in the book.
-
#end_date ⇒ Date
readonly
Date of the last transaction in the book.
-
#start_date ⇒ Date
readonly
Date of the first transaction in the book.
-
#transactions ⇒ Array<Transaction>
readonly
Transactions in the book.
Instance Method Summary collapse
-
#attributes ⇒ Array<Symbol>
Attributes available for inspection.
-
#find_account_by_full_name(full_name) ⇒ Account?
Return a handle to the Account object that has the given fully-qualified name.
-
#find_account_by_id(id) ⇒ Account?
Return a handle to the Account object that has the given GUID.
-
#find_customer_by_full_name(full_name) ⇒ Customer?
Return a handle to the Customer object that has the given fully-qualified name.
-
#initialize(fname) ⇒ Book
constructor
Construct a Book object.
Methods included from Support::LightInspect
Constructor Details
#initialize(fname) ⇒ Book
Construct a Book object.
Normally called internally by Gnucash.open.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gnucash/book.rb', line 32 def initialize(fname) begin @ng = Nokogiri.XML(Zlib::GzipReader.open(fname).read) rescue Zlib::GzipFile::Error @ng = Nokogiri.XML(File.read(fname)) end book_nodes = @ng.xpath('/gnc-v2/gnc:book') if book_nodes.count != 1 raise "Error: Expected to find one gnc:book entry" end @book_node = book_nodes.first build_customers build_accounts build_transactions finalize end |
Instance Attribute Details
#accounts ⇒ Array<Account> (readonly)
Returns Accounts in the book.
10 11 12 |
# File 'lib/gnucash/book.rb', line 10 def accounts @accounts end |
#customers ⇒ Array<Account> (readonly)
Returns Customers in the book.
14 15 16 |
# File 'lib/gnucash/book.rb', line 14 def customers @customers end |
#end_date ⇒ Date (readonly)
Returns Date of the last transaction in the book.
23 24 25 |
# File 'lib/gnucash/book.rb', line 23 def end_date @end_date end |
#start_date ⇒ Date (readonly)
Returns Date of the first transaction in the book.
20 21 22 |
# File 'lib/gnucash/book.rb', line 20 def start_date @start_date end |
#transactions ⇒ Array<Transaction> (readonly)
Returns Transactions in the book.
17 18 19 |
# File 'lib/gnucash/book.rb', line 17 def transactions @transactions end |
Instance Method Details
#attributes ⇒ Array<Symbol>
Attributes available for inspection
86 87 88 |
# File 'lib/gnucash/book.rb', line 86 def attributes %i[start_date end_date] end |
#find_account_by_full_name(full_name) ⇒ Account?
Return a handle to the Account object that has the given fully-qualified name.
65 66 67 |
# File 'lib/gnucash/book.rb', line 65 def find_account_by_full_name(full_name) @accounts.find { |a| a.full_name == full_name } end |
#find_account_by_id(id) ⇒ Account?
Return a handle to the Account object that has the given GUID.
54 55 56 |
# File 'lib/gnucash/book.rb', line 54 def find_account_by_id(id) @accounts.find { |a| a.id == id } end |
#find_customer_by_full_name(full_name) ⇒ Customer?
Return a handle to the Customer object that has the given fully-qualified name.
78 79 80 |
# File 'lib/gnucash/book.rb', line 78 def find_customer_by_full_name(full_name) @customers.find { |a| a.full_name == full_name } end |