2 require 'accountregister'
4 ################################################################################
5 # Exports transactions to and imports transactions from tab-delimited input.
6 ################################################################################
10 File.open(@filename) do |file|
11 file.each_line do |line|
13 next if line =~ /^#|^$/ # ignore blank, comment lines
14 add(import_transaction(line))
20 File.open(@filename, "w") do |file|
22 exported_transaction = [
27 transaction.description
29 file.puts(exported_transaction)
35 def import_transaction(line)
36 transaction_values = line.split(/\t/, -1) # [from, to, amount, date, desc]
37 from, to, amount, date, description = transaction_values
38 from = @account_register.open(*from.split('.'))
39 to = @account_register.open(*to.split('.'))
41 date = Date.parse(date)
42 Transaction.new(from, to, amount, date, description)
45 def export_transaction(transaction)