Class: RustPdf::Bookmark
- Inherits:
-
Object
- Object
- RustPdf::Bookmark
- Defined in:
- lib/rustpdf.rb
Overview
A document outline (bookmark) entry. Nest with #child to build a tree. Each #add_bookmark call on a Document appends one root tree (pre-order flattened into parallel arrays).
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#page ⇒ Object
Returns the value of attribute page.
-
#title ⇒ Object
Returns the value of attribute title.
-
#top ⇒ Object
Returns the value of attribute top.
Instance Method Summary collapse
-
#child(bookmark) ⇒ Object
Append a child bookmark; returns self for chaining.
-
#flatten_into(level, out) ⇒ Object
Pre-order flatten into
outas [level, title, page, top] tuples. -
#initialize(title, page, top: nil, children: nil) ⇒ Bookmark
constructor
A new instance of Bookmark.
Constructor Details
#initialize(title, page, top: nil, children: nil) ⇒ Bookmark
Returns a new instance of Bookmark.
124 125 126 127 128 129 |
# File 'lib/rustpdf.rb', line 124 def initialize(title, page, top: nil, children: nil) @title = title @page = page @top = top @children = children || [] end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
122 123 124 |
# File 'lib/rustpdf.rb', line 122 def children @children end |
#page ⇒ Object
Returns the value of attribute page.
122 123 124 |
# File 'lib/rustpdf.rb', line 122 def page @page end |
#title ⇒ Object
Returns the value of attribute title.
122 123 124 |
# File 'lib/rustpdf.rb', line 122 def title @title end |
#top ⇒ Object
Returns the value of attribute top.
122 123 124 |
# File 'lib/rustpdf.rb', line 122 def top @top end |
Instance Method Details
#child(bookmark) ⇒ Object
Append a child bookmark; returns self for chaining.
132 133 134 135 |
# File 'lib/rustpdf.rb', line 132 def child(bookmark) @children << bookmark self end |
#flatten_into(level, out) ⇒ Object
Pre-order flatten into out as [level, title, page, top] tuples.
138 139 140 141 142 |
# File 'lib/rustpdf.rb', line 138 def flatten_into(level, out) out << [level, title, page, top] children.each { |c| c.flatten_into(level + 1, out) } out end |