open both plain text and gzipped gnucash files
This commit is contained in:
parent
022337f980
commit
c66f46da9a
@ -9,7 +9,11 @@ module Gnucash
|
|||||||
attr_accessor :end_date
|
attr_accessor :end_date
|
||||||
|
|
||||||
def initialize(fname)
|
def initialize(fname)
|
||||||
|
begin
|
||||||
@ng = Nokogiri.XML(Zlib::GzipReader.open(fname).read)
|
@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')
|
book_nodes = @ng.xpath('/gnc-v2/gnc:book')
|
||||||
if book_nodes.count != 1
|
if book_nodes.count != 1
|
||||||
raise "Error: Expected to find one gnc:book entry"
|
raise "Error: Expected to find one gnc:book entry"
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
describe Gnucash do
|
describe Gnucash do
|
||||||
|
describe '.open' do
|
||||||
|
it 'opens a gzipped gnucash book' do
|
||||||
|
book = Gnucash.open("spec/books/sample.gnucash")
|
||||||
|
book.is_a?(Gnucash::Book).should be_true
|
||||||
|
end
|
||||||
|
it 'opens a plain text gnucash book' do
|
||||||
|
book = Gnucash.open("spec/books/sample-text.gnucash")
|
||||||
|
book.is_a?(Gnucash::Book).should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user