Class: PDF::Reader::Explore
- Inherits:
-
Object
- Object
- PDF::Reader::Explore
- Defined in:
- lib/pdf/reader/explore.rb
Class Method Summary collapse
Instance Method Summary collapse
- #cd(path) ⇒ Object
- #document(root) ⇒ Object
-
#initialize(receiver, xref) ⇒ Explore
constructor
A new instance of Explore.
- #ls(entry = nil) ⇒ Object
- #output_child(obj) ⇒ Object
- #output_parent(obj) ⇒ Object
- #pwd ⇒ Object
Constructor Details
#initialize(receiver, xref) ⇒ Explore
Returns a new instance of Explore.
36 37 38 39 |
# File 'lib/pdf/reader/explore.rb', line 36 def initialize (receiver, xref) @xref = xref @pwd = '/' end |
Class Method Details
Instance Method Details
#cd(path) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/pdf/reader/explore.rb', line 72 def cd (path) path = path.to_s if path[0,1] == "/" @pwd = path else @pwd = Pathname.new(@pwd + '/' + path).cleanpath.to_s end end |
#document(root) ⇒ Object
41 42 43 44 |
# File 'lib/pdf/reader/explore.rb', line 41 def document (root) @root = root self end |
#ls(entry = nil) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/pdf/reader/explore.rb', line 86 def ls (entry = nil) parts = @pwd.split('/') obj = @root parts.shift if parts[0] == "" parts.push(entry) if entry parts.each do |p| case obj when Hash unless obj.has_key?(p) puts "invalid path at #{p}" return end obj = obj[p] when Array obj = obj[p.to_i] end obj = @xref.object(obj) end output_parent(obj) "#{@pwd}: #{obj.class}" end |
#output_child(obj) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/pdf/reader/explore.rb', line 61 def output_child (obj) print ": #{obj.class}" case obj when Float print ": #{obj}" when String print ": #{obj[0, 20].sub(/\n/, ' ')}" end end |
#output_parent(obj) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/pdf/reader/explore.rb', line 46 def output_parent (obj) case obj when Hash obj.each do |k,v| print "#{k}"; output_child(v); print "\n" Explore::const_set(k, k) if !Explore.const_defined?(k) end when Array obj.each_with_index {|o, i| print "#{i}: "; output_child(o); print "\n"} else output_child(obj) print "\n" end end |
#pwd ⇒ Object
82 83 84 |
# File 'lib/pdf/reader/explore.rb', line 82 def pwd @pwd end |