Module: CapybaraTable::XPath

Extended by:
XPath
Includes:
XPath
Included in:
XPath
Defined in:
lib/capybara_table.rb

Instance Method Summary collapse

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_positionObject



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(caption)
  descendant(:table)[descendant(:caption).string.n.is(caption)]
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