Sha256: dffe4a0b8d7818eae0b8a24f42a98665e382166c65b2f95e90685cfd9c9df044

Contents?: true

Size: 1.66 KB

Versions: 3

Compression:

Stored size: 1.66 KB

Contents

module Symbiont
  module WebObjects
    
    class Table < WebObject
      include Enumerable
      
      # This method is used to return a TableRow object based on the index provided. When
      # the index provided is a string, the text will be matched with the text from the first
      # column.
      # @return [Symbiont::WebObjects::TableRow]
      def [](index)
        index = find_by_title(index) if index.kind_of?(String)
        return nil unless index
        Object::Symbiont::WebObjects::TableRow.new(@web_object[index])
      end
      
      # This method is an iterator that returns a TableRow object each time through
      # the loop.
      # @return [Symbiont::WebObjects::TableRow]
      def each
        for index in 1..self.rows do
          yield self[index - 1]
        end
      end
      
      # This method will return the number of rows in a table.
      def rows
        @web_object.wd.find_elements(:xpath, row_xpath).size
      end
      
      # Returns a reference to the first row web object of a table.
      # @return [Symbiont::WebObjects::TableRow]
      def first_row
        self[0]
      end
      
      # Returns a reference to the last row web object of a table.
      # @return [Symbiont::WebObjects::TableRow]
      def last_row
        self[-1]
      end
      
      protected
      
      def row_xpath
        ".//child::tr"
      end
      
      private
      
      def find_by_title(row_text)
        @web_object.rows.find_index {|row| row[0].text == row_text}
      end
      
    end # class: Table
    
    ::Symbiont::WebObjects.class_for_tag[:table] = ::Symbiont::WebObjects::Table
    
  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.rb
symbiont-0.1.6 lib/symbiont/web_objects/table.rb
symbiont-0.1.5 lib/symbiont/web_objects/table.rb