Class: Spinach::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/spinach/parser.rb,
lib/spinach/parser/visitor.rb

Overview

Parser leverages GherkinRuby to parse the feature definition.

Defined Under Namespace

Classes: Visitor

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Parser

Returns a new instance of Parser.

Parameters:

  • content (String)

    The content to parse.



12
13
14
# File 'lib/spinach/parser.rb', line 12

def initialize(content)
  @content = content
end

Instance Attribute Details

#contentString (readonly)

Gets the plain text content out of the feature file.

Returns:

  • (String)

    The plain feature content.



30
31
32
# File 'lib/spinach/parser.rb', line 30

def content
  @content
end

Class Method Details

.open_file(filename) ⇒ Object

Parameters:

  • filename (String)

    The filename to parse.



20
21
22
# File 'lib/spinach/parser.rb', line 20

def self.open_file(filename)
  new File.read(filename)
end

Instance Method Details

#parseFeature

Parses the feature file and returns a Feature.

Returns:



38
39
40
41
# File 'lib/spinach/parser.rb', line 38

def parse
  ast = GherkinRuby.parse(@content + "\n")
  Visitor.new.visit(ast)
end