class FileTreeXML

Public Class Methods

new(x, debug: false) click to toggle source
# File lib/filetree_xml.rb, line 11
def initialize(x, debug: false)

  @debug = debug
  
  case x.strip
  when /^<\?polyrex/
    @px = Polyrex.new
    @px.import x
  when /</
    @px = Polyrex.new x
  else
    puts 'importing  schemaless raw document' if debug
    @px = Polyrex.new schema: 'files[title,tags]/filex[title]'
    @px.import x
  end

end

Public Instance Methods

ls(path='.') click to toggle source
# File lib/filetree_xml.rb, line 29
def ls(path='.')
  
  return @px.xpath './records/filex/summary/title/text()' if path == '.'

  a = path.split('/')

  xpath = if a.length > 1 then
    a.map {|x| "records/filex[summary/title='%s']" % x }.join('/')
  else
    "records/filex[summary/title='%s']" % path 
  end

  @px.xpath xpath + '/records/filex/summary/title/text()'
end