Module: Vapir::TableRow

Extended by:
ElementHelper
Defined in:
lib/vapir-common/elements/elements.rb

Instance Method Summary collapse

Methods included from ElementHelper

add_specifier, container_collection_method, container_single_method, included

Methods included from ElementClassAndModuleMethods

#add_container_method_extra_args, #all_dom_attr_aliases, #all_dom_attrs, #class_array_append, #class_array_get, #class_hash_get, #class_hash_merge, #container_collection_methods, #container_method_extra_args, #container_single_methods, #default_how, #dom_attr, #dom_attr_locate_alias, #dom_function, #dom_setter, #element_collection, #factory, #inspect_these, #inspect_this_if, #parent_element_module, #set_or_get_class_var, #specifiers

Instance Method Details

#[](index) ⇒ Object

returns the TableCell at the specified index



800
801
802
# File 'lib/vapir-common/elements/elements.rb', line 800

def [](index)
  cells[index]
end

#cell(first = nil, second = nil) ⇒ Object

returns a TableCell which is a cell of this of this row (not in a nested table). takes the usual arguments for specifying what you want - see github.com/vapir/vapir/wiki/Locators



787
788
789
# File 'lib/vapir-common/elements/elements.rb', line 787

def cell(first=nil, second=nil)
  element_by_howwhat(element_class_for(Vapir::TableCell), first, second, :extra => {:candidates => :cells})
end

#cell_at_column(index) ⇒ Object

returns the cell of the current row at the given column index (starting from 0), taking into account conSpans of other cells.

returns nil if index is greater than the number of columns of this row.



833
834
835
836
837
838
839
840
# File 'lib/vapir-common/elements/elements.rb', line 833

def cell_at_column(index)
  #TODO: test
  cells.each_by_index do |cell|
    index=index-(cell.colSpan || 1)
    return cell if index < 0
  end
  nil
end

#cell_at_column!(index) ⇒ Object

returns the cell of the current row at the given column index (starting from 0), taking into account conSpans of other cells.

raises exception if the cell does not exist (that is, index is greater than the number of columns of this row).



846
847
848
849
# File 'lib/vapir-common/elements/elements.rb', line 846

def cell_at_column!(index)
  #TODO: test
  cell_at_column(index) || raise(Vapir::Exception::UnknownObjectException, "Unable to locate cell at column #{index}. Column count is #{column_count}\non container: #{@container.inspect}")
end

#cell_countObject

the number of cells in this row



812
813
814
# File 'lib/vapir-common/elements/elements.rb', line 812

def cell_count
  cells.length
end

#column_countObject

the number of columns in this row, accounting for cells with a colspan attribute greater than 1



805
806
807
808
809
# File 'lib/vapir-common/elements/elements.rb', line 805

def column_count
  cells.inject(0) do |count, cell|
    count+ (cell.colSpan || 1)
  end
end

#column_count_whereObject

returns the column index (starting at 0), taking into account colspans, of the table cell for which the given block returns true.

if nothing matches the block, returns nil.



819
820
821
822
823
824
825
826
827
# File 'lib/vapir-common/elements/elements.rb', line 819

def column_count_where # :yields: table_cell
  cells.inject(0) do |count, cell|
    if yield cell
      return count
    end
    count+(cell.colSpan || 1)
  end
  nil
end

#each_cellObject Also known as: each

Iterate over each cell in the row. same as #cells.each.



792
793
794
795
796
# File 'lib/vapir-common/elements/elements.rb', line 792

def each_cell
  cells.each do |cell|
    yield cell
  end
end