add Account class; build from Book
This commit is contained in:
parent
b4d352dade
commit
2d42346541
@ -1,3 +1,4 @@
|
||||
require "gnucash/account"
|
||||
require "gnucash/book"
|
||||
require "gnucash/version"
|
||||
|
||||
|
9
lib/gnucash/account.rb
Normal file
9
lib/gnucash/account.rb
Normal 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
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user