Class: Celerity::Table

Inherits:
Element show all
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

#browser

Attributes inherited from Element

#container

Instance Method Summary collapse

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

#short_inspect

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

#cellsCelerity::TableCells



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.

Parameters:

  • index (Fixnum)

    The index of the wanted cell, 1-indexed.

Returns:

Raises:



97
98
99
100
101
102
103
104
105
# File 'lib/celerity/elements/table.rb', line 97

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...>

Parameters:

  • index (Fixnum)

    The index of the wanted row, 1-indexed.

Returns:

Raises:



76
77
78
79
80
81
82
83
84
# File 'lib/celerity/elements/table.rb', line 76

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

Parameters:

  • index (Fixnum) (defaults to: Celerity.index_offset)

    An index, 1-indexed (optional).

Returns:

  • (Fixnum)


124
125
126
127
# File 'lib/celerity/elements/table.rb', line 124

def column_count(index = Celerity.index_offset)
  assert_exists
  @object.getRow(index - Celerity.index_offset).getCells.length
end

#column_values(column_number) ⇒ Object



144
145
146
# File 'lib/celerity/elements/table.rb', line 144

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.

Yield Parameters:



60
61
62
63
# File 'lib/celerity/elements/table.rb', line 60

def each
  assert_exists
  @rows.each { |row| yield TableRow.new(self, :object, row)  }
end

#locateObject



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_countFixnum

The number of rows in the table

Returns:

  • (Fixnum)


112
113
114
115
# File 'lib/celerity/elements/table.rb', line 112

def row_count
  assert_exists
  @object.getRowCount
end

#row_values(row_number) ⇒ Object



148
149
150
# File 'lib/celerity/elements/table.rb', line 148

def row_values(row_number)
  (0..column_count(row_number)-1).map { |index| self[row_number][index + Celerity.index_offset].text }
end

#rowsCelerity::TableRows

Returns:



41
42
43
44
# File 'lib/celerity/elements/table.rb', line 41

def rows
  assert_exists
  TableRows.new(self, :object, @rows)
end

#to_aArray<Array<String>>

Returns the text of each cell in the the table as a two-dimensional array.

Returns:

  • (Array<Array<String>>)


134
135
136
137
138
139
140
141
142
# File 'lib/celerity/elements/table.rb', line 134

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