Sha256: 96d3bc5bfc16d429609ac11f617c30b7adbdef738073b747907e8870d5af1c35

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

module CukeModeler

  # A class modeling a step table row.

  class TableRow

    include Sourceable
    include Raw
    include Nested


    # The cells that make up the row
    attr_accessor :cells


    # Creates a new TableRow object and, if *source* is provided, populates
    # the object.
    def initialize(source = nil)
      parsed_row = process_source(source)

      @cells = []

      build_row(parsed_row) if parsed_row
    end

    # Returns a gherkin representation of the table row.
    def to_s
      "| #{cells.join(' | ')} |"
    end


    private


    def process_source(source)
      case
        when source.is_a?(String)
          parse_row(source)
        else
          source
      end
    end

    def parse_row(source_text)
      base_file_string = "Feature: Fake feature to parse\nScenario:\n* fake step\n"
      source_text = base_file_string + source_text

      parsed_file = Parsing::parse_text(source_text)

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

    def build_row(parsed_row)
      populate_element_source_line(parsed_row)
      populate_row_cells(parsed_row)
      populate_raw_element(parsed_row)
    end

    def populate_row_cells(parsed_row)
      @cells = parsed_row['cells']
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cuke_modeler-0.0.2 lib/cuke_modeler/table_row.rb
cuke_modeler-0.0.1 lib/cuke_modeler/table_row.rb