Class: QIF
- Inherits:
-
Object
- Object
- QIF
- Defined in:
- lib/csv2qif/qif.rb
Constant Summary collapse
- COLUMNS =
('a'..'z').to_a
- QIF_CODES =
[ [:date, :D], [:amount, :T], [:cleared, :C, 'Cleared Status'], [:num, :N, 'Num (check or reference number)'], [:payee, :P], [:memo, :M], [:address, :A, 'Address (up to five lines; the sixth line is an optional message)'], [:category, :L, 'Category (Category/Subcategory/Transfer/Class)'] ]
Instance Method Summary collapse
- #block ⇒ Object
- #header(row) ⇒ Object
- #method_missing(sym, *args, &block) ⇒ Object
- #push(row) ⇒ Object
- #reset(stream, options) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
51 52 53 |
# File 'lib/csv2qif/qif.rb', line 51 def method_missing(sym, *args, &block) @row[COLUMNS.index(sym.to_s)] end |
Instance Method Details
#block ⇒ Object
21 22 23 |
# File 'lib/csv2qif/qif.rb', line 21 def block Proc.new {} end |
#header(row) ⇒ Object
25 26 27 |
# File 'lib/csv2qif/qif.rb', line 25 def header row end |
#push(row) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/csv2qif/qif.rb', line 29 def push row @row = row return unless @options[:where].nil? or call_or_eval(:where) QIF_CODES.each do |key, code| next unless value = call_or_eval(key) case key when :date then put_line code, (value.instance_of?(Date) ? value : @options[:date_format] ? Date.strptime(value, @options[:date_format]) : Date.parse(value, true)).strftime("%m/%d/%Y") when :amount then put_line code, sprintf("%.2f", value.to_f) when :address then put_lines code, value, 5 when :category then @options[:mappings].each {|condition, pattern, replacement| value.gsub!(pattern, replacement) if call_or_eval_or_value condition} if @options[:mappings] put_line code, value else put_line code, value end end @stream.puts '^' end |
#reset(stream, options) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/csv2qif/qif.rb', line 14 def reset stream, @stream = stream @options = #options.keys.each { |m| undef_method m } stream.puts"!Type:#{[:type]}" end |