class Tapout::YamlParser
The TAP-Y Parser takes a TAP-Y stream and routes it through a tapout report format.
Constants
- END_DOCUMENT
- NEW_DOCUMENT
Public Class Methods
new(options={})
click to toggle source
# File lib/tapout/parsers/yaml.rb, line 16 def initialize(options={}) format = options[:format] input = options[:input] @reporter = Reporters.factory(format).new @input = input || $stdin @resume = NEW_DOCUMENT end
Public Instance Methods
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/yaml.rb, line 32 def consume(input=nil) @input = input if input entry = '' while line = @input.gets case line when PAUSE_DOCUMENT @resume = RESUME_DOCUMENT passthru when RESUME_DOCUMENT # (no effect) when END_DOCUMENT handle(entry) @resume = NEW_DOCUMENT entry = passthru when NEW_DOCUMENT handle(entry) entry = line else entry << line end end handle(entry) # in case final `...` was left out @reporter.finalize #@reporter.exit_code end
Also aliased as: read
handle(entry)
click to toggle source
Handle document entry.
Returns nothing.
# File lib/tapout/parsers/yaml.rb, line 65 def handle(entry) return if entry == RESUME_DOCUMENT stripped = entry.strip return if stripped.empty? return if stripped == "---" begin data = YAML.load(entry) @reporter << data rescue Psych::SyntaxError passthru(entry) end end
Also aliased as: <<
passthru(doc=nil)
click to toggle source
Passthru incoming data directly to `$stdout`.
# File lib/tapout/parsers/yaml.rb, line 85 def passthru(doc=nil) $stdout << doc if doc while line = @input.gets return line if @resume === line $stdout << line end return '' end