Class: Xembly::Xpath

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

Overview

XPATH directive

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Xpath

Ctor.

path

Path



30
31
32
# File 'lib/xembly/xpath.rb', line 30

def initialize(path)
  @path = path
end

Instance Method Details

#exec(dom, cursor) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/xembly/xpath.rb', line 34

def exec(dom, cursor)
  if @path.start_with?('/')
    after = dom.xpath(@path)
  else
    after = []
    cursor.each do |node|
      node.xpath(@path).each { |n| after.push(n) }
    end
  end
  after
end