Class: Fluentxpath::XPath

Inherits:
Object
  • Object
show all
Defined in:
lib/fluentxpath.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeXPath



16
17
18
# File 'lib/fluentxpath.rb', line 16

def initialize
  @expression = ""
end

Instance Attribute Details

#expressionObject

Returns the value of attribute expression.



8
9
10
# File 'lib/fluentxpath.rb', line 8

def expression
  @expression
end

Class Method Details

.that_navigates(&block) ⇒ Object



10
11
12
13
14
# File 'lib/fluentxpath.rb', line 10

def self.that_navigates(&block)
  xpath = self.new
  xpath.instance_eval(&block)
  return xpath.expression
end

Instance Method Details

#and_attribute(attributes) ⇒ Object



62
63
64
# File 'lib/fluentxpath.rb', line 62

def and_attribute(attributes)
  with_attributes(attributes)
end

#and_attributes(attributes) ⇒ Object



58
59
60
# File 'lib/fluentxpath.rb', line 58

def and_attributes(attributes)
  with_attributes(attributes)
end

#and_name(name) ⇒ Object



36
37
38
# File 'lib/fluentxpath.rb', line 36

def and_name(name)
  with_name(name)
end

#and_thenObject



40
41
42
# File 'lib/fluentxpath.rb', line 40

def and_then
  return self
end

#to_any_elementObject



28
29
30
# File 'lib/fluentxpath.rb', line 28

def to_any_element
  add "//"
end

#to_childrenObject



44
45
46
# File 'lib/fluentxpath.rb', line 44

def to_children
  add "/"
end

#to_descendantsObject



48
49
50
# File 'lib/fluentxpath.rb', line 48

def to_descendants
  add "//"
end

#to_root_elementObject



24
25
26
# File 'lib/fluentxpath.rb', line 24

def to_root_element
  add "/"
end

#to_root_nodeObject



20
21
22
# File 'lib/fluentxpath.rb', line 20

def to_root_node
  add "/"
end

#with_attribute(attributes) ⇒ Object



66
67
68
# File 'lib/fluentxpath.rb', line 66

def with_attribute(attributes)
  with_attributes(attributes)
end

#with_attributes(attributes) ⇒ Object



52
53
54
55
56
# File 'lib/fluentxpath.rb', line 52

def with_attributes(attributes)
  predicates = []
  attributes.each_pair { |attribute, value| predicates << "@#{attribute}='#{value}'" }
  add "[#{predicates.sort.join(" and ")}]"
end

#with_name(name) ⇒ Object



32
33
34
# File 'lib/fluentxpath.rb', line 32

def with_name(name)
  add name
end