Sha256: 5f81baa3a9d9efdb5190812bc2d674d45f286582a385c046322af7448ee82919

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

module CucumberAnalytics

  # A class modeling the table of a Step.

  class Table

    # The parent object that contains *self*
    attr_accessor :parent_element

    # 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)
      @contents = table.collect { |row| row['cells'] }
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cucumber_analytics-1.1.1 lib/cucumber_analytics/table.rb
cucumber_analytics-1.0.0 lib/cucumber_analytics/table.rb