Class: RustPdf::Bookmark

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#childrenObject

Returns the value of attribute children.



122
123
124
# File 'lib/rustpdf.rb', line 122

def children
  @children
end

#pageObject

Returns the value of attribute page.



122
123
124
# File 'lib/rustpdf.rb', line 122

def page
  @page
end

#titleObject

Returns the value of attribute title.



122
123
124
# File 'lib/rustpdf.rb', line 122

def title
  @title
end

#topObject

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