Class: PolyrexLinks

Inherits:
Polyrex
  • Object
show all
Defined in:
lib/polyrex-links.rb

Instance Method Summary collapse

Constructor Details

#initialize(x = 'links/link[name,url]') ⇒ PolyrexLinks

Returns a new instance of PolyrexLinks.



9
10
11
# File 'lib/polyrex-links.rb', line 9

def initialize(x='links/link[name,url]')
  super(x)
end

Instance Method Details

#locate(path) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/polyrex-links.rb', line 13

def locate(path)
  
  a = path.split('/')
  a2 = []
  (a2 << a.clone; a.pop) while a.any?

  mask = "records/link[summary/name='%s']"
  
  begin 
    c = a2.shift; xpath = c.map{|x| mask % x}.join + '/summary/url/text()'
    r = self.element xpath 
  end until r or a2.empty?
  
  # return the found path along with any remaining string which 
  #   it didn't find, or it will return nil.
  r ? [r + path.sub(c.join('/'),''), path.sub(c.join('/'),'')] : nil
end