Class: XPath::Expression::Applied

Inherits:
XPath::Expression show all
Defined in:
lib/xpath/expression.rb

Constant Summary

Constants included from XPath

VERSION

Instance Method Summary collapse

Methods inherited from XPath::Expression

#and, #apply, #current, #equals, #inverse, #is, #next_sibling, #normalize, #one_of, #or, #string_literal, #to_s, #to_xpaths, #union, #where, #wrap_xpath

Methods included from XPath

#anywhere, #attr, #child, #contains, #css, #current, #descendant, generate, #name, #string, #tag, #text, #var, #varstring

Constructor Details

#initialize(expression, variables = {}) ⇒ Applied

Returns a new instance of Applied.



210
211
212
213
# File 'lib/xpath/expression.rb', line 210

def initialize(expression, variables={})
  @variables = variables
  @expression = expression
end

Instance Method Details

#to_xpath(predicate = nil) ⇒ Object



215
216
217
218
219
220
221
# File 'lib/xpath/expression.rb', line 215

def to_xpath(predicate=nil)
  @expression.to_xpath(predicate) % @variables
rescue ArgumentError # for ruby < 1.9 compat
  @expression.to_xpath(predicate).gsub(/%\{(\w+)\}/) do |_|
    @variables[$1.to_sym] or raise(ArgumentError, "expected variable #{$1} to be set")
  end
end