Class: RubyReduce::InputReader

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_reduce/input_reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_name) ⇒ InputReader

Returns a new instance of InputReader.



3
4
5
6
7
# File 'lib/ruby_reduce/input_reader.rb', line 3

def initialize(file_name)
  @output = []
  @file_name = file_name

end

Instance Method Details

#emit_chunk(key, chunk) ⇒ Object



9
10
11
# File 'lib/ruby_reduce/input_reader.rb', line 9

def emit_chunk(key, chunk)
  @output << [key, chunk]
end

#readObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ruby_reduce/input_reader.rb', line 13

def read
  current_chunks = []
  in_error = false

  File.new(@file_name).each do |line|
    if line =~ /^Started/ && line =~ /newrelic/
    elsif line =~ /^Started/
      current_chunks << [line]
    elsif line =~ /^Completed \d/ 
      current_chunks.first << line
      emit_chunk(@file_name, current_chunks.first.join(''))
      current_chunks.delete_at 0
    elsif line =~ /^Completed(\s)*in/
      in_error = true
      current_chunks.first << line
    elsif in_error && line =~ /within rescues\/layout/
      in_error = false
      current_chunks.first << line
      emit_chunk(@file_name, current_chunks.first.join(''))
      current_chunks.delete_at 0
    elsif line == '' || line == "\n"
    else
      current_chunks.first << line if current_chunks.first
    end
  end

  @output
end