Class: Webrat::Table

Inherits:
Element
  • Object
show all
Defined in:
lib/cucumber/webrat/table_locator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.xpath_searchObject



3
4
5
# File 'lib/cucumber/webrat/table_locator.rb', line 3

def self.xpath_search
  ".//table"
end

Instance Method Details

#to_aObject

Converts this Table element into an Array of Array of String where each cell represents the inner_html of the <td> and <th> elements. The number of columns is determined by the number of cells in the first row.



10
11
12
13
14
15
16
17
18
19
# File 'lib/cucumber/webrat/table_locator.rb', line 10

def to_a
  col_count = nil
  Webrat::XML.css_search(@element, 'tr').map do |row|
    cols = Webrat::XML.css_search(row, 'th,td')
    col_count ||= cols.length
    cols[0...col_count].map do |col|
      col.inner_html
    end
  end
end