Sha256: f8edc5e79f6ae2525f1dd20c4fa6fc3247275334683d631d77dd221bc695e6e5

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module CucumberAnalytics

  # A class modeling the table of a Step.

  class Table

    include Raw
    include Nested


    # The contents of the table
    attr_accessor :contents


    # Creates a new Table object and, if *source* is provided, populates
    # the object.
    def initialize(source = nil)
      @contents = []

      parsed_table = process_source(source)

      build_table(parsed_table) if parsed_table
    end


    private


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

    def parse_table(source_text)
      base_file_string = "Feature:\nScenario:\n* step\n"
      source_text = base_file_string + source_text

      parsed_file = Parsing::parse_text(source_text)

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

    def build_table(table)
      populate_contents(table)
      populate_raw_element(table)
    end

    def populate_contents(table)
      @contents = table.collect { |row| row['cells'] }
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cucumber_analytics-1.3.0 lib/cucumber_analytics/table.rb