Method: QuickETL::QifFileReader#read

Defined in:
lib/quick_etl_qif_file_reader.rb

#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