Instances of this class represent a transaction parsed within an !Account section of a qif file.
# File lib/qiflib_transaction.rb, line 14 def self.csv_header CSV.generate do | csv | csv << Qiflib::csv_transaction_field_names end end
# File lib/qiflib_transaction.rb, line 20 def initialize(acct_owner=nil, acct_name=nil, acct_type=nil, source_app='quicken') if acct_owner @acct_owner = "#{acct_owner}".downcase @acct_name = "#{acct_name}".downcase @acct_type = "#{acct_type}".downcase @source_app = "#{source_app}".downcase @id, @date, @amount, @cleared, @category, @number, @memo, @payee = 0, nil, nil, '', '', '', '', '' @splits, @curr_split, @address, @ibank_n = [], {}, [], '' end end
# File lib/qiflib_transaction.rb, line 31 def add_line(line) if line stripped = line.strip if stripped.size > 0 # Field Indicator Explanations: # D Date # T Amount # C Cleared status # N Num (check or reference number) # P Payee # M Memo # A Address (up to five lines; the sixth line is an optional message) # L Category (Category/Subcategory/Transfer/Class) # S Category in split (Category/Transfer/Class) # E Memo in split # $ Dollar amount of split # ^ End of the entry if (stripped.match(/^D/)) @date = Qiflib::Date.new(line_value(stripped)) elsif (stripped.match(/^T/)) @amount = Qiflib::Money.new(line_value(stripped)) elsif (stripped.match(/^P/)) @payee = line_value(stripped) elsif (stripped.match(/^C/)) @cleared = line_value(stripped) elsif (stripped.match(/^N/)) @ibank_n = line_value(stripped) @number = line_value(stripped) elsif (stripped.match(/^M/)) @memo = line_value(stripped) elsif (stripped.match(/^L/)) @category = line_value(stripped).downcase elsif (stripped.match(/^S/)) @category = line_value(stripped).downcase if @category.size == 0 # default to first split category current_split['category'] = line_value(stripped).downcase elsif (stripped.match(/^E/)) current_split['memo'] = line_value(stripped) elsif (stripped.match(/^A/)) @address << line_value(stripped) elsif (stripped.match(/^\$/)) current_split['amount'] = Qiflib::Money.new(line_value(stripped)) splits << current_split @curr_split = {} end end end end
# File lib/qiflib_transaction.rb, line 101 def as_array(idx=0) array = [] array << idx + 1 array << acct_owner.downcase array << acct_name.downcase array << acct_type.downcase array << date.to_s array << amount.to_s array << number array << ibank_n array << cleared array << payee array << category array << memo 3.times { | i | if i < splits.size array << splits[i]['amount'].to_s array << splits[i]['category'] array << splits[i]['memo'] else array << '0.0' array << '' array << '' end } 6.times { | i | if i < address.size array << address[i] else array << '' end } array << 'x' array end
# File lib/qiflib_transaction.rb, line 90 def current_split @curr_split = {} if @curr_split.nil? @curr_split end
# File lib/qiflib_transaction.rb, line 79 def ibank? @source_app == 'ibank' end
# File lib/qiflib_transaction.rb, line 137 def line_value(s) return '' if s.nil? || s.size < 1 s[1, s.size].strip end
# File lib/qiflib_transaction.rb, line 95 def to_csv(idx=0) CSV.generate do | csv | csv << as_array(idx) end end
# File lib/qiflib_transaction.rb, line 83 def valid? return false if date.nil? return false if date.to_s.size < 8 return false if date.to_s == '0000-00-00' true end