Class: Cucumber::Gherkin::DataTableParser

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/gherkin/data_table_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(builder) ⇒ DataTableParser

Returns a new instance of DataTableParser



10
11
12
# File 'lib/cucumber/gherkin/data_table_parser.rb', line 10

def initialize(builder)
  @builder = builder
end

Instance Method Details

#feature_headerObject



24
25
26
27
28
29
30
# File 'lib/cucumber/gherkin/data_table_parser.rb', line 24

def feature_header
  dialect = ::Gherkin::Dialect.for('en')
  %(#{dialect.feature_keywords[0]}:
      #{dialect.scenario_keywords[0]}:
        #{dialect.given_keywords[0]} x
   )
end

#parse(text) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/cucumber/gherkin/data_table_parser.rb', line 14

def parse(text)
  token_scanner = ::Gherkin::TokenScanner.new(feature_header + text)
  parser = ::Gherkin::Parser.new
  gherkin_document = parser.parse(token_scanner)

  gherkin_document[:feature][:children][0][:steps][0][:argument][:rows].each do |row|
    @builder.row(row[:cells].map { |cell| cell[:value] })
  end
end