class Tapout::JsonParser

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

Public Class Methods

new(options={}) click to toggle source
# File lib/tapout/parsers/json.rb, line 13
def initialize(options={})
  format    = options[:format]
  @reporter = Reporters.factory(format).new
  @input    = options[:input] || $stdin

  @resume = RESUME_DOCUMENT
end

Public Instance Methods

<<(entry)

Alias for handle.

Alias for: handle
consume(input=nil) click to toggle source

Read from input using `gets` and parse, routing entries to reporter.

input - Input channel, defaults to $stdin. [#gets]

Returns reporter exit code.

# File lib/tapout/parsers/json.rb, line 26
def consume(input=nil)
  @input = input if input

  while line = input.gets
    case line
    when PAUSE_DOCUMENT
      passthru
    when RESUME_DOCUMENT  # has no effect here
    else
      handle(line)
    end
  end

  @reporter.finalize
end
Also aliased as: read
handle(entry) click to toggle source

Handle document entry.

Returns nothing.

# File lib/tapout/parsers/json.rb, line 48
def handle(entry)
  return if entry.empty?
  return if entry == RESUME_DOCUMENT

  begin
    data = JSON.load(entry)
    @reporter << data
  rescue JSON::ParserError
    passthru(entry)
  end
end
Also aliased as: <<
read(input=nil)

Alias for consume.

Alias for: consume