class Druid::Elements::Table
Public Instance Methods
[](what)
click to toggle source
Return the Druid::Elements::Table
for the index provided. Index is zero based. If the index provided is a String then it will be matched with the text from any column. The text can be a substring of the full column text.
@return [Druid::Elements::TableRow]
# File lib/druid/elements/table.rb, line 12 def [](what) idx = find_index(what) idx && row_items[idx] end
column_values(what)
click to toggle source
Returns the Array of values(String) in a column for the index provided. Index is zero based. If the index provided is a String then it will be matched with the text from the header. The text can be a substring of the full header text
# File lib/druid/elements/table.rb, line 56 def column_values(what) idx = find_index_of_header(what) idx && row_items.drop(1).collect{ |row| row.cell(index: idx).text } end
each(&block)
click to toggle source
iterator that yields with a Druid::Elements::TableRow
@return [Druid::Elements::TableRow]
# File lib/druid/elements/table.rb, line 29 def each(&block) row_items.each(&block) end
first_row()
click to toggle source
return the first row
@return Druid::Elements::TableRow
# File lib/druid/elements/table.rb, line 38 def first_row self[0] end
last_row()
click to toggle source
return the last row
@return Druid::Elements::TableRow
# File lib/druid/elements/table.rb, line 47 def last_row self[-1] end
rows()
click to toggle source
Returns the number of rows in the table.
# File lib/druid/elements/table.rb, line 20 def rows row_items.size end
Private Instance Methods
find_index(what)
click to toggle source
# File lib/druid/elements/table.rb, line 81 def find_index(what) return what if what.is_a? Integer row_items.find_index do |row| row.cell(text: /#{Regexp.escape(what)}/).exist? end end
find_index_of_header(what)
click to toggle source
# File lib/druid/elements/table.rb, line 74 def find_index_of_header(what) return what if what.is_a? Integer row_items[0].cells.find_index do |cell| cell.text.include? Regexp.escape(what) end end
row_items()
click to toggle source
# File lib/druid/elements/table.rb, line 63 def row_items meth = stragegy == :descendants ? :trs : :rows @row_items ||= element.send(meth).map do |obj| Druid::Elements::TableRow.new(obj) end end
stragegy()
click to toggle source
# File lib/druid/elements/table.rb, line 70 def stragegy :children end