Class: XPath::Expression::StringLiteral

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, #string_literal, #to_s, #to_xpaths, #union, #where, #wrap_xpath

Methods included from XPath

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

Constructor Details

#initialize(expression) ⇒ StringLiteral

Returns a new instance of StringLiteral.



115
116
117
# File 'lib/xpath/expression.rb', line 115

def initialize(expression)
  @expression = expression
end

Instance Method Details

#to_xpath(predicate = nil) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/xpath/expression.rb', line 119

def to_xpath(predicate=nil)
  @expression = @expression.to_xpath(predicate) unless @expression.is_a?(String)
  if @expression.include?("'")
    @expression = @expression.split("'", -1).map do |substr|
      "'#{substr}'"
    end.join(%q{,"'",})
    "concat(#{@expression})"
  else
    "'#{@expression}'"
  end
end