Sha256: 843dcc22665cd91e72e6b3e44fca3ab11a37c7c87d328f4e9d784781d4d8e537

Contents?: true

Size: 829 Bytes

Versions: 45

Compression:

Stored size: 829 Bytes

Contents

# encoding: utf-8

module Watir
  class Table < HTMLElement
    include RowContainer

    def hashes
      all_rows   = rows.to_a
      header_row = all_rows.shift or raise Exception::Error, "no rows in table"

      headers = header_row.ths.map { |header_cell| header_cell.text  }
      result = []

      all_rows.each_with_index do |row, idx|
        cells = row.cells.to_a
        if cells.length != headers.length
          raise Exception::Error, "row at index #{idx} has #{cells.length} cells, expected #{headers.length}"
        end

        result << headers.inject({}) { |res, header| res.merge(header => cells.shift.text) }
      end

      result
    end

    #
    # Get the n'th row of this table.
    #
    # @return Watir::TableRow
    #

    def [](idx)
      row(:index, idx)
    end

  end # Table
end # Watir

Version data entries

45 entries across 45 versions & 2 rubygems

Version Path
watir-webdriver-0.6.1 lib/watir-webdriver/elements/table.rb
watir-webdriver-0.6.0 lib/watir-webdriver/elements/table.rb
watir-webdriver-0.5.8 lib/watir-webdriver/elements/table.rb
watir-webdriver-0.5.7 lib/watir-webdriver/elements/table.rb
watir-webdriver-0.5.6 lib/watir-webdriver/elements/table.rb
watir-webdriver-0.5.5 lib/watir-webdriver/elements/table.rb
watir-webdriver-0.5.4 lib/watir-webdriver/elements/table.rb
watir-webdriver-0.5.3 lib/watir-webdriver/elements/table.rb
watir-webdriver-0.5.2 lib/watir-webdriver/elements/table.rb
watir-webdriver-0.5.1 lib/watir-webdriver/elements/table.rb
watir-webdriver-0.5.0 lib/watir-webdriver/elements/table.rb
watir-webdriver-0.4.1 lib/watir-webdriver/elements/table.rb
watir-webdriver-0.4.0 lib/watir-webdriver/elements/table.rb
watir-webdriver-0.3.9 lib/watir-webdriver/elements/table.rb
watir-webdriver-0.3.8 lib/watir-webdriver/elements/table.rb
watir-webdriver-0.3.7 lib/watir-webdriver/elements/table.rb
watir-webdriver-0.3.6 lib/watir-webdriver/elements/table.rb
watir-webdriver-0.3.5 lib/watir-webdriver/elements/table.rb
watir-webdriver-0.3.4 lib/watir-webdriver/elements/table.rb
watir-webdriver-0.3.3 lib/watir-webdriver/elements/table.rb