Method: Origami::PDF#ls

Defined in:
lib/origami/pdf.rb

#ls(pattern, follow_references: true) ⇒ Object

Returns an array of Objects whose name (in a Dictionary) is matching pattern.

Raises:

  • (TypeError)


263
264
265
266
267
268
269
270
271
# File 'lib/origami/pdf.rb', line 263

def ls(pattern, follow_references: true)

    pattern = /#{Regexp.escape(pattern)}/i if pattern.is_a?(::String)
    raise TypeError, "Expected a String or Regexp" unless pattern.is_a?(Regexp)

    self.grep(pattern, streams: false, object_streams: true)
        .select {|object| object.is_a?(Name) and object.parent.is_a?(Dictionary) and object.parent.key?(object) }
        .collect {|object| result = object.parent[object]; follow_references ? result.solve : result }
end