Class: XPath::Expression

Inherits:
Object
  • Object
show all
Includes:
XPath
Defined in:
lib/xpath/expression.rb

Direct Known Subclasses

Applied, Binary, Literal, Multiple, OneOf, Self, StringLiteral, Unary, Variable

Defined Under Namespace

Classes: And, Anywhere, Applied, Attribute, Binary, CSS, Child, Contains, Descendant, Equality, Inverse, Is, Literal, Multiple, Name, NextSibling, NormalizedSpace, OneOf, Or, Self, StringFunction, StringLiteral, Tag, Text, Unary, Variable, Where

Constant Summary

Constants included from XPath

VERSION

Instance Method Summary collapse

Methods included from XPath

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

Instance Method Details

#and(expression) ⇒ Object Also known as: &



260
261
262
# File 'lib/xpath/expression.rb', line 260

def and(expression)
  Expression::And.new(current, expression)
end

#apply(variables = {}) ⇒ Object



291
292
293
# File 'lib/xpath/expression.rb', line 291

def apply(variables={})
  Expression::Applied.new(current, variables)
end

#currentObject



229
230
231
# File 'lib/xpath/expression.rb', line 229

def current
  self
end

#equals(expression) ⇒ Object Also known as: ==



246
247
248
# File 'lib/xpath/expression.rb', line 246

def equals(expression)
  Expression::Equality.new(current, expression)
end

#inverseObject Also known as: ~



270
271
272
# File 'lib/xpath/expression.rb', line 270

def inverse
  Expression::Inverse.new(current)
end

#is(expression) ⇒ Object



251
252
253
# File 'lib/xpath/expression.rb', line 251

def is(expression)
  Expression::Is.new(current, expression)
end

#next_sibling(*expressions) ⇒ Object



233
234
235
# File 'lib/xpath/expression.rb', line 233

def next_sibling(*expressions)
  Expression::NextSibling.new(current, expressions)
end

#normalizeObject Also known as: n



295
296
297
# File 'lib/xpath/expression.rb', line 295

def normalize
  Expression::NormalizedSpace.new(current)
end

#one_of(*expressions) ⇒ Object



242
243
244
# File 'lib/xpath/expression.rb', line 242

def one_of(*expressions)
  Expression::OneOf.new(current, expressions)
end

#or(expression) ⇒ Object Also known as: |



255
256
257
# File 'lib/xpath/expression.rb', line 255

def or(expression)
  Expression::Or.new(current, expression)
end

#string_literalObject



275
276
277
# File 'lib/xpath/expression.rb', line 275

def string_literal
  Expression::StringLiteral.new(self)
end

#to_sObject



283
284
285
# File 'lib/xpath/expression.rb', line 283

def to_s
  to_xpaths.join(' | ')
end

#to_xpath(predicate = nil) ⇒ Object

Raises:

  • (NotImplementedError)


279
280
281
# File 'lib/xpath/expression.rb', line 279

def to_xpath(predicate=nil)
  raise NotImplementedError, "please implement in subclass"
end

#to_xpathsObject



287
288
289
# File 'lib/xpath/expression.rb', line 287

def to_xpaths
  [to_xpath(:exact), to_xpath(:fuzzy)].uniq
end

#union(*expressions) ⇒ Object Also known as: +



265
266
267
# File 'lib/xpath/expression.rb', line 265

def union(*expressions)
  Union.new(*[self, expressions].flatten)
end

#where(expression) ⇒ Object Also known as: []



237
238
239
# File 'lib/xpath/expression.rb', line 237

def where(expression)
  Expression::Where.new(current, expression)
end

#wrap_xpath(expression) ⇒ Object



300
301
302
303
304
305
306
# File 'lib/xpath/expression.rb', line 300

def wrap_xpath(expression)
  case expression
    when ::String then Expression::StringLiteral.new(expression)
    when ::Symbol then Expression::Literal.new(expression)
    else expression
  end
end