Class: TapOut::JsonParser

Inherits:
Object
  • Object
show all
Defined in:
lib/tapout/parsers/json.rb

Overview

The TAP-J Parser takes a TAP-J stream and routes it through a TapOut report format.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ JsonParser

Returns a new instance of JsonParser.



12
13
14
15
# File 'lib/tapout/parsers/json.rb', line 12

def initialize(options={})
  format    = options[:format]
  @reporter = Reporters.factory(format).new
end

Instance Method Details

#<<(line) ⇒ Object



26
27
28
# File 'lib/tapout/parsers/json.rb', line 26

def <<(line)
  handle(line)
end

#consume(input) ⇒ Object



18
19
20
21
22
23
# File 'lib/tapout/parsers/json.rb', line 18

def consume(input)
  while line = input.gets
    self << line
  end
  @reporter.finalize
end

#handle(doc) ⇒ Object



31
32
33
34
35
# File 'lib/tapout/parsers/json.rb', line 31

def handle(doc)
  return if doc == ''
  entry = JSON.load(doc)
  @reporter << entry
end