Sha256: 822954e450111212a2e8fa83a0047ecb544f8a8e973209b0f1c0273c4b529246

Contents?: true

Size: 1.31 KB

Versions: 4

Compression:

Stored size: 1.31 KB

Contents

module CukeModeler

  # A class modeling a single row of a step table or example table.

  class Row < Model

    include Sourceable
    include Parsing
    include Parsed

    # The cell models that make up the row
    attr_accessor :cells


    # Creates a new Row object and, if *source_text* is provided, populates
    # the object.
    def initialize(source_text = nil)
      @cells = []

      super(source_text)

      if source_text
        parsed_row_data = parse_source(source_text)
        populate_row(self, parsed_row_data)
      end
    end

    # Returns a string representation of this model. For a row model,
    # this will be Gherkin text that is equivalent to the row being modeled.
    def to_s
      text_cells = cells.collect { |cell| cell.to_s }

      "| #{text_cells.join(' | ')} |"
    end


    private


    def parse_source(source_text)
      base_file_string = "# language: #{Parsing.dialect}\n#{dialect_feature_keyword}: Fake feature to parse\n#{dialect_scenario_keyword}:\n#{dialect_step_keyword} fake step\n"
      source_text = base_file_string + source_text

      parsed_file = Parsing::parse_text(source_text, 'cuke_modeler_stand_alone_row.feature')

      parsed_file['feature']['elements'].first['steps'].first['table']['rows'].first
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cuke_modeler-3.3.0 lib/cuke_modeler/models/row.rb
cuke_modeler-3.2.0 lib/cuke_modeler/models/row.rb
cuke_modeler-3.1.0 lib/cuke_modeler/models/row.rb
cuke_modeler-3.0.0 lib/cuke_modeler/models/row.rb