Class: Tapout::YamlParser
- Inherits:
-
Object
- Object
- Tapout::YamlParser
- Defined in:
- lib/tapout/parsers/yaml.rb
Overview
The TAP-Y Parser takes a TAP-Y stream and routes it through a Tapout report format.
Instance Method Summary collapse
-
#<<(line) ⇒ Object
TODO: write this as a YAML stream parser.
- #consume(input) ⇒ Object
- #handle ⇒ Object
-
#initialize(options = {}) ⇒ YamlParser
constructor
A new instance of YamlParser.
- #stop ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ YamlParser
Returns a new instance of YamlParser.
12 13 14 15 16 17 |
# File 'lib/tapout/parsers/yaml.rb', line 12 def initialize(={}) format = [:format] @reporter = Reporters.factory(format).new @doc = '' @done = false end |
Instance Method Details
#<<(line) ⇒ Object
TODO: write this as a YAML stream parser
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/tapout/parsers/yaml.rb', line 31 def <<(line) case line when /^\-\-\-/ handle #@doc @doc << line when /^\.\.\./ handle #@doc stop else @doc << line end end |
#consume(input) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/tapout/parsers/yaml.rb', line 20 def consume(input) @doc = '' @done = false while line = input.gets self << line end handle unless @done # in case `...` was left out return @reporter.exit_code end |
#handle ⇒ Object
45 46 47 48 49 50 |
# File 'lib/tapout/parsers/yaml.rb', line 45 def handle return if @doc == '' entry = YAML.load(@doc) @reporter << entry @doc = '' end |
#stop ⇒ Object
53 54 55 |
# File 'lib/tapout/parsers/yaml.rb', line 53 def stop @done = true end |