Class: Qiflib::Transaction
- Inherits:
-
Object
- Object
- Qiflib::Transaction
- Defined in:
- lib/qiflib_transaction.rb
Overview
Instances of this class represent a transaction parsed within an !Account section of a qif file.
Instance Attribute Summary collapse
-
#acct_name ⇒ Object
constructor arg fields.
-
#acct_owner ⇒ Object
constructor arg fields.
-
#acct_type ⇒ Object
constructor arg fields.
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#amount ⇒ Object
readonly
data fields.
-
#category ⇒ Object
readonly
data fields.
-
#cleared ⇒ Object
readonly
data fields.
-
#date ⇒ Object
readonly
data fields.
-
#id ⇒ Object
computed field.
-
#memo ⇒ Object
readonly
data fields.
-
#number ⇒ Object
readonly
data fields.
-
#payee ⇒ Object
readonly
data fields.
-
#source_app ⇒ Object
constructor arg fields.
-
#splits ⇒ Object
readonly
Returns the value of attribute splits.
Class Method Summary collapse
Instance Method Summary collapse
- #add_line(line) ⇒ Object
- #as_array(idx = 0) ⇒ Object
- #current_split ⇒ Object
- #ibank? ⇒ Boolean
-
#initialize(acct_owner = nil, acct_name = nil, acct_type = nil, source_app = 'quicken') ⇒ Transaction
constructor
A new instance of Transaction.
- #line_value(s) ⇒ Object
- #to_csv(idx = 0) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(acct_owner = nil, acct_name = nil, acct_type = nil, source_app = 'quicken') ⇒ Transaction
Returns a new instance of Transaction.
20 21 22 23 24 25 26 27 28 29 |
# 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 = [], {}, [] end end |
Instance Attribute Details
#acct_name ⇒ Object
constructor arg fields
10 11 12 |
# File 'lib/qiflib_transaction.rb', line 10 def acct_name @acct_name end |
#acct_owner ⇒ Object
constructor arg fields
10 11 12 |
# File 'lib/qiflib_transaction.rb', line 10 def acct_owner @acct_owner end |
#acct_type ⇒ Object
constructor arg fields
10 11 12 |
# File 'lib/qiflib_transaction.rb', line 10 def acct_type @acct_type end |
#address ⇒ Object (readonly)
Returns the value of attribute address.
12 13 14 |
# File 'lib/qiflib_transaction.rb', line 12 def address @address end |
#amount ⇒ Object (readonly)
data fields
11 12 13 |
# File 'lib/qiflib_transaction.rb', line 11 def amount @amount end |
#category ⇒ Object (readonly)
data fields
11 12 13 |
# File 'lib/qiflib_transaction.rb', line 11 def category @category end |
#cleared ⇒ Object (readonly)
data fields
11 12 13 |
# File 'lib/qiflib_transaction.rb', line 11 def cleared @cleared end |
#date ⇒ Object (readonly)
data fields
11 12 13 |
# File 'lib/qiflib_transaction.rb', line 11 def date @date end |
#id ⇒ Object
computed field
9 10 11 |
# File 'lib/qiflib_transaction.rb', line 9 def id @id end |
#memo ⇒ Object (readonly)
data fields
11 12 13 |
# File 'lib/qiflib_transaction.rb', line 11 def memo @memo end |
#number ⇒ Object (readonly)
data fields
11 12 13 |
# File 'lib/qiflib_transaction.rb', line 11 def number @number end |
#payee ⇒ Object (readonly)
data fields
11 12 13 |
# File 'lib/qiflib_transaction.rb', line 11 def payee @payee end |
#source_app ⇒ Object
constructor arg fields
10 11 12 |
# File 'lib/qiflib_transaction.rb', line 10 def source_app @source_app end |
#splits ⇒ Object (readonly)
Returns the value of attribute splits.
12 13 14 |
# File 'lib/qiflib_transaction.rb', line 12 def splits @splits end |
Class Method Details
.csv_header ⇒ Object
14 15 16 17 18 |
# File 'lib/qiflib_transaction.rb', line 14 def self.csv_header CSV.generate do | csv | csv << Qiflib::csv_transaction_field_names end end |
Instance Method Details
#add_line(line) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# 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/)) @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 |
#as_array(idx = 0) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/qiflib_transaction.rb', line 100 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 << 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 |
#current_split ⇒ Object
89 90 91 92 |
# File 'lib/qiflib_transaction.rb', line 89 def current_split @curr_split = {} if @curr_split.nil? @curr_split end |
#ibank? ⇒ Boolean
78 79 80 |
# File 'lib/qiflib_transaction.rb', line 78 def ibank? @source_app == 'ibank' end |
#line_value(s) ⇒ Object
135 136 137 138 |
# File 'lib/qiflib_transaction.rb', line 135 def line_value(s) return '' if s.nil? || s.size < 1 s[1, s.size].strip end |
#to_csv(idx = 0) ⇒ Object
94 95 96 97 98 |
# File 'lib/qiflib_transaction.rb', line 94 def to_csv(idx=0) CSV.generate do | csv | csv << as_array(idx) end end |
#valid? ⇒ Boolean
82 83 84 85 86 87 |
# File 'lib/qiflib_transaction.rb', line 82 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 |