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.
73 74 75 76 77 78 |
# File 'lib/rustpdf.rb', line 73 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.
71 72 73 |
# File 'lib/rustpdf.rb', line 71 def children @children end |
#page ⇒ Object
Returns the value of attribute page.
71 72 73 |
# File 'lib/rustpdf.rb', line 71 def page @page end |
#title ⇒ Object
Returns the value of attribute title.
71 72 73 |
# File 'lib/rustpdf.rb', line 71 def title @title end |
#top ⇒ Object
Returns the value of attribute top.
71 72 73 |
# File 'lib/rustpdf.rb', line 71 def top @top end |
Instance Method Details
#child(bookmark) ⇒ Object
Append a child bookmark; returns self for chaining.
81 82 83 84 |
# File 'lib/rustpdf.rb', line 81 def child(bookmark) @children << bookmark self end |
#flatten_into(level, out) ⇒ Object
Pre-order flatten into out as [level, title, page, top] tuples.
87 88 89 90 91 |
# File 'lib/rustpdf.rb', line 87 def flatten_into(level, out) out << [level, title, page, top] children.each { |c| c.flatten_into(level + 1, out) } out end |