Class: Spinach::Parser

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

Overview

Parser leverages Gherkin to parse the feature definition.

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
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

#contentString (readonly)

Gets the plain text content out of the feature file.

Returns:

  • (String)

    The plain feature content.



32
33
34
# File 'lib/spinach/parser.rb', line 32

def content
  @content
end

Class Method Details

.open_file(filename) ⇒ Object

Parameters:

  • filename (String)

    The filename to parse.



22
23
24
# File 'lib/spinach/parser.rb', line 22

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

Instance Method Details

#parseHash

Parses the feature file and returns an AST as a Hash.

Returns:

  • (Hash)

    The parsed Gherkin output.



40
41
42
43
# File 'lib/spinach/parser.rb', line 40

def parse
  @parser.parse(content, @filename, __LINE__-1)
  @formatter.gherkin_object
end