Class: Celerity::Table
- Includes:
- ClickableElement, Container, Enumerable
- Defined in:
- lib/celerity/elements/table.rb
Constant Summary collapse
- TAGS =
[ Identifier.new('table') ]
- ATTRIBUTES =
BASE_ATTRIBUTES | [ :align, :bgcolor, :border, :cellpadding, :cellspacing, :frame, :rules, :summary, :width, ]
- DEFAULT_HOW =
:id
Constants inherited from Element
Element::BASE_ATTRIBUTES, Element::CELLHALIGN_ATTRIBUTES, Element::CELLVALIGN_ATTRIBUTES, Element::HTML_401_TRANSITIONAL
Instance Attribute Summary
Attributes included from Container
Attributes inherited from Element
Instance Method Summary collapse
- #cells ⇒ Celerity::TableCells (also: #tds)
-
#child_cell(index) ⇒ Celerity::TableCell
Returns the TableCell at the given index (1-indexed).
-
#child_row(index) ⇒ Celerity::TableRow
(also: #[])
Returns the TableRow at the given index (1-indexed).
-
#column_count(index = Celerity.index_offset) ⇒ Fixnum
Returns the number of columns on the row at the given index.
- #column_values(column_number) ⇒ Object
-
#each {|row| ... } ⇒ Object
Iterates through each row in the table.
- #locate ⇒ Object
-
#row_count ⇒ Fixnum
The number of rows in the table.
- #row_values(row_number) ⇒ Object
- #rows ⇒ Celerity::TableRows
-
#to_a ⇒ Array<Array<String>>
Returns the text of each cell in the the table as a two-dimensional array.
Methods included from Container
#area, #areas, #button, #buttons, #cell, #check_box, #checkboxes, #container=, #contains_text, #dd, #dds, #del, #dels, #div, #divs, #dl, #dls, #dt, #dts, #em, #ems, #file_field, #file_fields, #form, #forms, #frame, #frames, #h1, #h1s, #h2, #h2s, #h3, #h3s, #h4, #h4s, #h5, #h5s, #h6, #h6s, #hidden, #hiddens, #image, #images, #ins, #inses, #inspect, #label, #labels, #li, #link, #links, #lis, #map, #maps, #meta, #metas, #ol, #ols, #option, #p, #pre, #pres, #ps, #radio, #radios, #row, #select_list, #select_lists, #span, #spans, #strong, #strongs, #table, #tables, #tbodies, #tbody, #text_field, #text_fields, #tfoot, #tfoots, #th, #thead, #theads, #ths, #ul, #uls
Methods included from ShortInspect
Methods included from ClickableElement
#click, #click_and_attach, #double_click, #download, #right_click
Methods inherited from Element
#==, #assert_exists, #attribute_string, #attribute_value, #exists?, #fire_event, #focus, #focused?, #initialize, #javascript_object, #method_missing, #methods, #object, #parent, #respond_to?, #text, #to_s, #to_xml, #visible?, #xpath
Constructor Details
This class inherits a constructor from Celerity::Element
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Celerity::Element
Instance Method Details
#cells ⇒ Celerity::TableCells Also known as: tds
50 51 52 53 |
# File 'lib/celerity/elements/table.rb', line 50 def cells assert_exists TableCells.new(self, :object, @cells) end |
#child_cell(index) ⇒ Celerity::TableCell
Returns the TableCell at the given index (1-indexed).
In a 10-column row, table.child_cell will return the first cell on the second row.
98 99 100 101 102 103 104 105 106 |
# File 'lib/celerity/elements/table.rb', line 98 def child_cell(index) assert_exists if (index - Celerity.index_offset) >= @cells.length raise UnknownCellException, "Unable to locate a cell at index #{index}" end TableCell.new(self, :object, @cells[index - Celerity.index_offset]) end |
#child_row(index) ⇒ Celerity::TableRow Also known as: []
Returns the TableRow at the given index (1-indexed).
browser.table(:foo, 'bar')[1] # => #<TableRow...>
browser.table(:foo, 'bar').child_row[1] # => #<TableRow...>
77 78 79 80 81 82 83 84 85 |
# File 'lib/celerity/elements/table.rb', line 77 def child_row(index) assert_exists if (index - Celerity.index_offset) >= @rows.length raise UnknownRowException, "Unable to locate a row at index #{index}" end TableRow.new(self, :object, @rows[index - Celerity.index_offset]) end |
#column_count(index = Celerity.index_offset) ⇒ Fixnum
Returns the number of columns on the row at the given index. (1-indexed) Default is the number of columns on the first row
125 126 127 128 |
# File 'lib/celerity/elements/table.rb', line 125 def column_count(index = Celerity.index_offset) assert_exists @object.getRow(index - Celerity.index_offset).getCells.length end |
#column_values(column_number) ⇒ Object
145 146 147 |
# File 'lib/celerity/elements/table.rb', line 145 def column_values(column_number) (0..row_count-1).map { |index| self[index + Celerity.index_offset][column_number].text } end |
#each {|row| ... } ⇒ Object
Iterates through each row in the table.
61 62 63 64 |
# File 'lib/celerity/elements/table.rb', line 61 def each assert_exists @rows.each { |row| yield TableRow.new(self, :object, row) } end |
#locate ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/celerity/elements/table.rb', line 22 def locate super if @object @rows = @object.getRows @cells = [] @rows.each do |row| row.getCells.each do |c| @cells << c end end end @object end |
#row_count ⇒ Fixnum
The number of rows in the table
113 114 115 116 |
# File 'lib/celerity/elements/table.rb', line 113 def row_count assert_exists @object.getRowCount end |
#row_values(row_number) ⇒ Object
149 150 151 |
# File 'lib/celerity/elements/table.rb', line 149 def row_values(row_number) (0..column_count(row_number)-1).map { |index| self[row_number][index + Celerity.index_offset].text } end |
#rows ⇒ Celerity::TableRows
41 42 43 44 |
# File 'lib/celerity/elements/table.rb', line 41 def rows assert_exists TableRows.new(self, :object, @rows) end |
#to_a ⇒ Array<Array<String>>
Returns the text of each cell in the the table as a two-dimensional array.
135 136 137 138 139 140 141 142 143 |
# File 'lib/celerity/elements/table.rb', line 135 def to_a assert_exists # @object.getRows.map do |table_row| # table_row.getCells.map { |td| td.asText.strip } # end rows.map do |table_row| table_row.map { |td| td.text } end end |