Class: FileTreeXML
- Inherits:
-
Object
- Object
- FileTreeXML
- Defined in:
- lib/filetree_xml.rb
Instance Method Summary collapse
-
#initialize(x, debug: false) ⇒ FileTreeXML
constructor
A new instance of FileTreeXML.
- #ls(path = '.') ⇒ Object
Constructor Details
#initialize(x, debug: false) ⇒ FileTreeXML
Returns a new instance of FileTreeXML.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/filetree_xml.rb', line 12 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]/file[title]' @px.import x end end |
Instance Method Details
#ls(path = '.') ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/filetree_xml.rb', line 30 def ls(path='.') return @px.xpath './records/file/summary/title/text()' if path == '.' a = path.split('/') xpath = if a.length > 1 then a.map {|x| "records/file[summary/title='%s']" % x }.join('/') else "records/file[summary/title='%s']" % path end @px.xpath xpath + '/records/file/summary/title/text()' end |