Class: Pdfrb::Document::OutlineEntry
- Inherits:
-
Object
- Object
- Pdfrb::Document::OutlineEntry
- Defined in:
- lib/pdfrb/document/outline.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#dest ⇒ Object
readonly
Returns the value of attribute dest.
-
#oid ⇒ Object
Returns the value of attribute oid.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #add_child(entry) ⇒ Object
- #build!(document) ⇒ Object
-
#initialize(title:, dest:, document:) ⇒ OutlineEntry
constructor
A new instance of OutlineEntry.
Constructor Details
#initialize(title:, dest:, document:) ⇒ OutlineEntry
Returns a new instance of OutlineEntry.
71 72 73 74 75 76 77 78 |
# File 'lib/pdfrb/document/outline.rb', line 71 def initialize(title:, dest:, document:) @title = title @dest = dest @document = document @children = [] @value = {} @oid = nil end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
68 69 70 |
# File 'lib/pdfrb/document/outline.rb', line 68 def children @children end |
#dest ⇒ Object (readonly)
Returns the value of attribute dest.
68 69 70 |
# File 'lib/pdfrb/document/outline.rb', line 68 def dest @dest end |
#oid ⇒ Object
Returns the value of attribute oid.
69 70 71 |
# File 'lib/pdfrb/document/outline.rb', line 69 def oid @oid end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
68 69 70 |
# File 'lib/pdfrb/document/outline.rb', line 68 def title @title end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
68 69 70 |
# File 'lib/pdfrb/document/outline.rb', line 68 def value @value end |
Instance Method Details
#add_child(entry) ⇒ Object
80 81 82 83 |
# File 'lib/pdfrb/document/outline.rb', line 80 def add_child(entry) @children << entry entry end |
#build!(document) ⇒ Object
85 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 112 113 114 115 116 |
# File 'lib/pdfrb/document/outline.rb', line 85 def build!(document) dict = document.add( { Title: @title, Parent: nil, }, type: Pdfrb::Model::Cos::Dictionary ) dict.value[:Dest] = @dest if @dest @oid = dict.oid @value = dict.value if @children.any? first_child = nil prev_child = nil @children.each do |child| child_ref = child.build!(document) child.value[:Parent] = Pdfrb::Model::Reference.new(dict.oid, dict.gen) child.value[:Prev] = prev_child.value ? Pdfrb::Model::Reference.new(prev_child.oid, 0) : nil if prev_child prev_child&.value&.[]=(:Next, Pdfrb::Model::Reference.new(child_ref.oid, 0)) first_child ||= child_ref prev_child = child end dict.value[:First] = Pdfrb::Model::Reference.new(first_child.oid, 0) dict.value[:Last] = Pdfrb::Model::Reference.new(prev_child.oid, 0) dict.value[:Count] = @children.length end dict end |