Class: Pdfrb::Document::Destinations
- Inherits:
-
Object
- Object
- Pdfrb::Document::Destinations
- Defined in:
- lib/pdfrb/document/destinations.rb
Overview
Named-destinations facade. Manages both name-tree destinations (Catalog /Names /Dests) and the explicit /Dests dictionary.
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Look up a named destination by name.
-
#add(name, destination) ⇒ Object
Add an explicit destination under
name. - #count ⇒ Object
-
#each_name ⇒ Object
Enumerate all destination names (from both /Dests and /Names/Dests).
- #empty? ⇒ Boolean
-
#initialize(document) ⇒ Destinations
constructor
A new instance of Destinations.
- #names ⇒ Object
Constructor Details
#initialize(document) ⇒ Destinations
Returns a new instance of Destinations.
10 11 12 |
# File 'lib/pdfrb/document/destinations.rb', line 10 def initialize(document) @document = document end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
8 9 10 |
# File 'lib/pdfrb/document/destinations.rb', line 8 def document @document end |
Instance Method Details
#[](name) ⇒ Object
Look up a named destination by name. Returns the destination array or nil.
16 17 18 19 20 21 22 |
# File 'lib/pdfrb/document/destinations.rb', line 16 def [](name) dests_dict = resolved_explicit_dict return dests_dict[name] if dests_dict && dests_dict[name] name_tree = resolved_name_tree lookup_in_name_tree(name_tree, name) end |
#add(name, destination) ⇒ Object
Add an explicit destination under name. Creates the /Dests
dictionary if absent. destination is typically an Array
[page_ref, fit_keyword, *args].
27 28 29 30 31 32 33 |
# File 'lib/pdfrb/document/destinations.rb', line 27 def add(name, destination) ensure_dictionaries catalog = document.catalog catalog.value[:Dests] ||= {} catalog.value[:Dests][name.to_sym] = destination name.to_sym end |
#count ⇒ Object
65 66 67 |
# File 'lib/pdfrb/document/destinations.rb', line 65 def count names.size end |
#each_name ⇒ Object
Enumerate all destination names (from both /Dests and /Names/Dests).
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pdfrb/document/destinations.rb', line 36 def each_name(&) return enum_for(:each_name) unless block_given? seen = Set.new explicit = resolved_explicit_dict explicit&.each_key do |k| next if seen.include?(k) seen << k yield k end name_tree = resolved_name_tree each_name_tree_key(name_tree) do |k| next if seen.include?(k) seen << k yield k end end |
#empty? ⇒ Boolean
61 62 63 |
# File 'lib/pdfrb/document/destinations.rb', line 61 def empty? names.empty? end |
#names ⇒ Object
57 58 59 |
# File 'lib/pdfrb/document/destinations.rb', line 57 def names each_name.to_a end |