Class: Spinach::Parser
- Inherits:
-
Object
- Object
- Spinach::Parser
- Defined in:
- lib/spinach/parser.rb
Overview
Parser leverages Gherkin to parse the feature definition.
Instance Attribute Summary collapse
-
#content ⇒ String
readonly
Gets the plain text content out of the feature file.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(content) ⇒ Parser
constructor
A new instance of Parser.
-
#parse ⇒ Hash
Parses the feature file and returns an AST as a Hash.
Constructor Details
#initialize(content) ⇒ Parser
Returns a new instance of Parser.
12 13 14 15 16 |
# File 'lib/spinach/parser.rb', line 12 def initialize(content) @content = content @formatter = Gherkin::Formatter::JSONFormatter.new(nil) @parser = Gherkin::Parser::Parser.new(@formatter) end |
Instance Attribute Details
#content ⇒ String (readonly)
Gets the plain text content out of the feature file.
32 33 34 |
# File 'lib/spinach/parser.rb', line 32 def content @content end |
Class Method Details
.open_file(filename) ⇒ Object
22 23 24 |
# File 'lib/spinach/parser.rb', line 22 def self.open_file(filename) new File.read(filename) end |
Instance Method Details
#parse ⇒ Hash
Parses the feature file and returns an AST as a Hash.
40 41 42 43 |
# File 'lib/spinach/parser.rb', line 40 def parse @parser.parse(content, @filename, __LINE__-1) @formatter.gherkin_object end |