add Account class; build from Book

This commit is contained in:
josh committed 2013-07-30 22:44:11 -04:00
1 parent b4d352dade
commit 2d42346541
3 files changed
+26

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
module Gnucash
class Account
def initialize(book, node)
@node = node
@name = node.xpath('act:name').text
@type = node.xpath('act:type').text
end
end
end
+16
View File
@@ -3,8 +3,24 @@ require "nokogiri"
module Gnucash
class Book
attr_accessor :accounts
def initialize(fname)
@ng = Nokogiri.XML(Zlib::GzipReader.open(fname).read)
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_accounts
end
private
def build_accounts
@accounts = @book_node.xpath('gnc:account').map do |act_node|
Account.new(self, act_node)
end
end
end
end