module LapisLazuli::GenericModule::XPath

Helper functions for XPath composition

Public Instance Methods

xp_and(first, second) click to toggle source

Constructs xpath and clause

# File lib/lapis_lazuli/generic/xpath.rb, line 30
def xp_and(first, second)
  return "(#{first} and #{second})"
end
xp_contains(node, needle, separator = ' ') click to toggle source

Return an xpath contains clause for e.g. checking wether an element's class attribute node contains a string. The optional third parameter determines how substrings are separated in the attribute node; the default is space for matching class names. Note that enclosing [ and ] are not included in the return value; this lets you more easily use and()/or()/not() operators.

# File lib/lapis_lazuli/generic/xpath.rb, line 23
def xp_contains(node, needle, separator = ' ')
  contains = "contains(concat('#{separator}', normalize-space(#{node}), '#{separator}'), '#{separator}#{needle}#{separator}')"
  return contains
end
xp_not(expr) click to toggle source

Constructs xpath or clause

# File lib/lapis_lazuli/generic/xpath.rb, line 42
def xp_not(expr)
  return "not(#{expr})"
end
xp_or(first, second) click to toggle source

Constructs xpath or clause

# File lib/lapis_lazuli/generic/xpath.rb, line 36
def xp_or(first, second)
  return "(#{first} or #{second})"
end