Class: QuickETL::QifFileReader

Inherits:
QuickETLObject show all
Defined in:
lib/quick_etl_qif_file_reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from QuickETLKernel

#command_line_arg, #command_line_array_arg, #command_line_boolean_arg, #default_delimiter, #display_general_info, #display_usage_instructions, #get_array_property, #get_property, #home_dir, #line_value, #load_properties, #parse_qif_files, #project_author, #project_copyright, #project_date, #project_embedded_comment, #project_license, #project_name, #project_version_number, #project_year, #read_as_ascii_lines, #read_lines, #startup, #strip_lines, #tokenize, #usage_instructions, #write_file, #write_lines

Constructor Details

#initialize(owner, filename, debug = false) ⇒ QifFileReader

Returns a new instance of QifFileReader.



19
20
21
22
23
24
25
# File 'lib/quick_etl_qif_file_reader.rb', line 19

def initialize(owner, filename, debug=false)
  @owner    = owner
  @filename = filename
  @debug    = debug
  @transactions = Array.new
  read
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



17
18
19
# File 'lib/quick_etl_qif_file_reader.rb', line 17

def debug
  @debug
end

#filenameObject

Returns the value of attribute filename.



17
18
19
# File 'lib/quick_etl_qif_file_reader.rb', line 17

def filename
  @filename
end

#transactionsObject

Returns the value of attribute transactions.



17
18
19
# File 'lib/quick_etl_qif_file_reader.rb', line 17

def transactions
  @transactions
end

Instance Method Details

#add_transaction(t) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/quick_etl_qif_file_reader.rb', line 74

def add_transaction(t)
  t.parse
  if t.valid
    @transactions.push(t)
  else
    puts "invalid trans"
  end
end

#readObject



27
28
29
30
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
# File 'lib/quick_etl_qif_file_reader.rb', line 27

def read
  @lines = read_as_ascii_lines(@filename, 13, false)
  in_tran_zone    = false
  in_acct_header  = false    
  @acct_name   = ''
  @acct_type   = '' 
  line_num     = 0
  tran         = QifTran.new(@owner, @acct_name, @acct_type, 0)   
  start_token  = '!Type:Class'

  @lines.each { | line |
    line_num = line_num + 1
  
    if (line == start_token) 
      in_tran_zone = true
      next
    end
  
    if (line.match(/^!Account/))
      in_acct_header = true
      next
    end
    
    if in_acct_header
      if (line.match(/^N/))
        @acct_name = (line_value(line))
        tran.acct_name = @acct_name
      elsif (line.match(/^T/))
        @acct_type = (line_value(line)) 
        tran.acct_type = @acct_type        
      elsif (line == '^')
        in_acct_header = false
      end
      next
    end
        
    if in_tran_zone       
      if (line == '^')
        add_transaction(tran)
        tran = QifTran.new(@owner, @acct_name, @acct_type, line_num)
      else     
        tran.add_line(line)
      end
    end
  }   
end

#to_sObject



85
86
87
# File 'lib/quick_etl_qif_file_reader.rb', line 85

def to_s
  "QifFileReader #{@filename} #{@lines.size} #{@transactions.size}"
end