Class: Groonga::GrntestLog::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga/grntest-log.rb

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



161
162
# File 'lib/groonga/grntest-log.rb', line 161

def initialize
end

Instance Method Details

#parse(input, &block) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/groonga/grntest-log.rb', line 164

def parse(input, &block)
  in_environment = false
  buffer = ""
  input.each_line do |line|
    if in_environment
      case line
      when "},\n"
        buffer << "}"
        yield(EnvironmentEvent.new(parse_json(buffer)))
        buffer.clear
        in_environment = false
      else
        buffer << line
      end
    else
      case line
      when /\A\[\{"script":/
        buffer << line[1..-1]
        in_environment = true
      when /\A\{"jobs":/
        yield(JobsStartEvent.new(parse_json(line.sub(/,$/, "}"))))
      when /\A"detail": \[$/
        # ignore
      when /\A\[\d+,/
        yield(TaskEvent.new(*parse_json(line.sub(/\]+,$/, "]"))))
      when /\A"summary": /
        summaries = parse_json(line.gsub(/(?:\A"summary": |\},$)/, ''))
        summaries = summaries.collect do |summary|
          JobSummaryEvent.new(summary)
        end
        yield(JobsEndEvent.new(summaries))
      end
    end
  end
end