Sha256: d9bb1e53db88b6bd011a43f02aadca70f158b99f2080d8f65a4643439f8338f3

Contents?: true

Size: 1.5 KB

Versions: 3

Compression:

Stored size: 1.5 KB

Contents

module Symbiont
  module WebObjects
    
    class TableRow < WebObject
      include Enumerable
      
      # This method is used to return a TableCell object based on the index provided. When
      # the index provided is a string, the text will be matched with the text from the
      # columns in the first row.
      # @return [Symbiont::WebObjects::TableCell]
      def [](index)
        index = find_by_title(index) if index.kind_of?(String)
        return nil unless index
        Object::Symbiont::WebObjects::TableCell.new(@web_object[index])
      end
      
      # This method is an iterator that returns a TableCell object each time through
      # the loop.
      # @return [Symbiont::WebObjects::TableCell]
      def each
        for index in 1..self.columns do
          yield self[index - 1]
        end
      end
      
      # This method returns the number of columns in a table object.
      def columns
        @web_object.wd.find_elements(:xpath, cell_xpath).size
      end
      
      protected
      
      def cell_xpath
        ".//child::td|th"
      end
      
      private
      
      def find_by_title(column_text)
        table = @web_object.parent
        table = table.parent if table.tag_name == 'tbody'
        first_row = table[0]
        first_row.cells.find_index {|column| column.text.include? column_text}
      end
      
    end # class: TableRow
    
    ::Symbiont::WebObjects.class_for_tag[:tr] = ::Symbiont::WebObjects::TableRow
    
  end # module: WebObjects
end # module: Symbiont

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
symbiont-0.1.7 lib/symbiont/web_objects/table_row.rb
symbiont-0.1.6 lib/symbiont/web_objects/table_row.rb
symbiont-0.1.5 lib/symbiont/web_objects/table_row.rb