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.



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

def initialize(builder)
  @builder = builder
end

Instance Method Details

#feature_headerObject



36
37
38
39
40
41
42
# File 'lib/cucumber/gherkin/data_table_parser.rb', line 36

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

#gherkin_optionsObject



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

def gherkin_options
  {
    include_source: false,
    include_gherkin_document: true,
    include_pickles: false
  }
end

#parse(text) ⇒ Object



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

def parse(text)
  gherkin_document = nil
  messages = ::Gherkin.from_source('dummy', feature_header + text, gherkin_options)

  messages.each do |message|
    gherkin_document = message.gherkin_document.to_h unless message.gherkin_document.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