lib/symbiont/web_objects/table.rb in symbiont-0.1.1 vs lib/symbiont/web_objects/table.rb in symbiont-0.1.2
- old
+ new
@@ -1,13 +1,17 @@
module Symbiont
module WebObjects
class Table < WebObject
+ include Enumerable
- # This method is used to return a TableRow object based on the index provided.
+ # 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)
Object::Symbiont::WebObjects::TableRow.new(@web_object[index])
end
# This method is an iterator that returns a TableRow object each time through
# the loop.
@@ -37,9 +41,15 @@
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
end # module: WebObjects