Class: CapybaraPageObject::TableElement

Inherits:
Element
  • Object
show all
Includes:
Enumerable
Defined in:
lib/capybara_page_object/elements/table_element.rb

Instance Attribute Summary

Attributes inherited from Element

#element, #page

Instance Method Summary collapse

Methods inherited from Element

#attribute, #class, #enabled?, #focus, #html, #initialize, #method_missing, #native, #parent, #respond_to_missing?, #scroll_into_view, #within

Constructor Details

This class inherits a constructor from CapybaraPageObject::Element

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CapybaraPageObject::Element

Instance Method Details

#[](row_index) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/capybara_page_object/elements/table_element.rb', line 11

def [](row_index)
  if row_index.kind_of?(String)
    rows.find do |row|
      row.columns.any? {|col| col.text.include?(row_index) }
    end
  else
    rows[row_index]
  end
end

#as_hashesObject



21
22
23
24
25
# File 'lib/capybara_page_object/elements/table_element.rb', line 21

def as_hashes
  rows[1..-1].map do |row|
    Hash[headers.zip(row.map(&:text))]
  end
end

#eachObject



5
6
7
8
9
# File 'lib/capybara_page_object/elements/table_element.rb', line 5

def each
  for index in 1..self.rows.length do
    yield self[index-1]
  end
end

#first_rowObject



41
42
43
# File 'lib/capybara_page_object/elements/table_element.rb', line 41

def first_row
  rows[0]
end

#headersObject



45
46
47
# File 'lib/capybara_page_object/elements/table_element.rb', line 45

def headers
  rows[0].columns.map(&:text)
end

#last_rowObject



36
37
38
39
# File 'lib/capybara_page_object/elements/table_element.rb', line 36

def last_row
  the_rows = rows
  the_rows[the_rows.length - 1]
end

#rowsObject



28
29
30
31
32
33
34
# File 'lib/capybara_page_object/elements/table_element.rb', line 28

def rows
  within do
    all(:xpath, ".//child::tr").map do |row|
      TableRowElement.new(row, page, self)
    end
  end
end