Skip to content

Commit

Permalink
Merge pull request #3 from jonbartlett/master
Browse files Browse the repository at this point in the history
support for writing multiple Account entries
  • Loading branch information
davidsklar committed Sep 3, 2015
2 parents 5078fb4 + 362fc4d commit fb0e2db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/qif/writer.rb
Expand Up @@ -60,7 +60,7 @@ def initialize(io, type = 'Bank', format = 'dd/mm/yyyy')
end
end

# Add a transaction for writing
# Add a QIF entry for writing
def <<(transaction)
case transaction.class.to_s
when "Qif::Transaction"
Expand Down Expand Up @@ -89,7 +89,9 @@ def write_header
end

def write_account
write_record(@accounts.first.to_s) # only one account per file
@accounts.each do |a|
write_record(a)
end
end

def write_transactions
Expand Down
11 changes: 11 additions & 0 deletions spec/lib/writer_spec.rb
Expand Up @@ -60,6 +60,17 @@
@buffer.should include('NExpenses:Eating and Drinking:Coffee')
end

it 'should write multiple accounts' do

Qif::Writer.new(@io) do |writer|
writer << Qif::Account.new(:name => 'Expenses:Eating and Drinking:Coffee')
writer << Qif::Account.new(:name => 'Expenses:Eating and Drinking:Tea')
end

@buffer.should include('NExpenses:Eating and Drinking:Coffee')
@buffer.should include('NExpenses:Eating and Drinking:Tea')
end

it 'should write the transactions' do
date = Time.now

Expand Down

0 comments on commit fb0e2db

Please sign in to comment.