Module: CapybaraTable::XPath
Instance Method Summary collapse
- #cell_position(node) ⇒ Object
- #header_position(header) ⇒ Object
- #self_position ⇒ Object
- #table(caption) ⇒ Object
- #table_cell(header, value) ⇒ Object
- #table_row(fields) ⇒ Object
Instance Method Details
#cell_position(node) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/capybara_table.rb', line 34 def cell_position(node) siblings = node.preceding_sibling(:td, :th) without_colspan = siblings[attr(:colspan).inverse].count with_colspan = siblings.attr(:colspan).sum exists = node.boolean.number without_colspan.plus(with_colspan).plus(exists) end |
#header_position(header) ⇒ Object
29 30 31 32 |
# File 'lib/capybara_table.rb', line 29 def header_position(header) header_node = ancestor(:table)[1].descendant(:tr)[1].descendant(:th)[string.n.is(header)] cell_position(header_node) end |
#self_position ⇒ Object
25 26 27 |
# File 'lib/capybara_table.rb', line 25 def self_position cell_position(self_axis) end |
#table(caption) ⇒ Object
11 12 13 |
# File 'lib/capybara_table.rb', line 11 def table() descendant(:table)[descendant(:caption).string.n.is()] end |
#table_cell(header, value) ⇒ Object
21 22 23 |
# File 'lib/capybara_table.rb', line 21 def table_cell(header, value) descendant(:td, :th)[string.n.is(value).and(header_position(header).equals(self_position))] end |
#table_row(fields) ⇒ Object
15 16 17 18 19 |
# File 'lib/capybara_table.rb', line 15 def table_row(fields) fields.reduce(descendant(:tr)) do |xpath, (header, value)| xpath[table_cell(header, value)] end end |