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, 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, #text, #var, #varstring

Instance Method Details

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



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

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

#apply(variables = {}) ⇒ Object



285
286
287
# File 'lib/xpath/expression.rb', line 285

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

#currentObject



223
224
225
# File 'lib/xpath/expression.rb', line 223

def current
  self
end

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



240
241
242
# File 'lib/xpath/expression.rb', line 240

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

#inverseObject Also known as: ~



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

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

#is(expression) ⇒ Object



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

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

#next_sibling(*expressions) ⇒ Object



227
228
229
# File 'lib/xpath/expression.rb', line 227

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

#normalizeObject Also known as: n



289
290
291
# File 'lib/xpath/expression.rb', line 289

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

#one_of(*expressions) ⇒ Object



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

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

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



249
250
251
# File 'lib/xpath/expression.rb', line 249

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

#string_literalObject



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

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

#to_sObject



277
278
279
# File 'lib/xpath/expression.rb', line 277

def to_s
  to_xpaths.join(' | ')
end

#to_xpath(predicate = nil) ⇒ Object

Raises:

  • (NotImplementedError)


273
274
275
# File 'lib/xpath/expression.rb', line 273

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

#to_xpathsObject



281
282
283
# File 'lib/xpath/expression.rb', line 281

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

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



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

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

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



231
232
233
# File 'lib/xpath/expression.rb', line 231

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

#wrap_xpath(expression) ⇒ Object



294
295
296
297
298
299
300
# File 'lib/xpath/expression.rb', line 294

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