Class: Rind::Nodes

Inherits:
Array
  • Object
show all
Defined in:
lib/rind/nodes.rb

Direct Known Subclasses

Children

Instance Method Summary collapse

Instance Method Details

#exact_index(node) ⇒ Object

Returns the index of the first object in self such that it is equal? to the node.



4
5
6
7
8
9
# File 'lib/rind/nodes.rb', line 4

def exact_index(node)
  self.each_index do |index|
    return index if self[index].equal?(node)
  end
  nil
end

#filter(path) ⇒ Object

Return only the nodes that match the Xpath provided.



12
13
14
15
16
17
18
# File 'lib/rind/nodes.rb', line 12

def filter(path)
  # if the path doesn't have an axis then default to "self"
  if path !~ /^([.\/]|(.+?::))/
    path = "self::#{path}"
  end
  Nodes.new(self.find_all{|node| not node.s(path).empty?})
end