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_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) ⇒ StringLiteral

Returns a new instance of StringLiteral.



124
125
126
# File 'lib/xpath/expression.rb', line 124

def initialize(expression)
  @expression = expression
end

Instance Method Details

#to_xpath(predicate = nil) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/xpath/expression.rb', line 128

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