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


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

def initialize(builder)
  @builder = builder
end

Instance Method Details

#feature_headerObject


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

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


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

def parse(text)
  gherkin_document = nil
  messages = ::Gherkin::Gherkin.from_source('dummy', feature_header + text, include_source: false, include_pickles: false)
  messages.each do |message|
    gherkin_document = message.gherkinDocument.to_hash unless message.gherkinDocument.nil?
  end

  return if gherkin_document.nil?
  gherkin_document[:feature][:children][0][:scenario][:steps][0][:data_table][:rows].each do |row|
    @builder.row(row[:cells].map { |cell| cell[:value] })
  end
end