Class: PDF::Core::NameTree::Node Private
- Inherits:
-
Object
- Object
- PDF::Core::NameTree::Node
- Defined in:
- lib/pdf/core/name_tree.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Name Tree node
Instance Attribute Summary collapse
-
#children ⇒ Array<Node>
readonly
private
Child nodes.
-
#document ⇒ Prawn::Document
readonly
private
-
#limit ⇒ Integer
readonly
private
Children number limit.
-
#parent ⇒ Node
private
Parent node.
-
#ref ⇒ Reference
private
Instance Method Summary collapse
-
#<<(value) ⇒ value
private
Insert value maintaining order and rebalancing tree if needed.
-
#>=(other) ⇒ Boolean
private
This is a compatibility method to allow uniform comparison between nodes and values.
-
#add(name, value) ⇒ Object
private
Adds a value.
-
#deep_copy ⇒ Node
private
Returns a deep copy of this node, without copying expensive things like the
ref
todocument
. -
#empty? ⇒ Boolean
private
Tells whether there are any children nodes.
-
#greatest ⇒ String
private
The greatest (in lexicographic order) value name.
-
#initialize(document, limit, parent = nil) ⇒ Node
constructor
private
A new instance of Node.
-
#leaf? ⇒ Boolean
private
Tells whether this is a leaf node.
-
#least ⇒ String
private
The least (in lexicographic order) value name.
-
#size ⇒ Integer
private
Number of all (including nested) children nodes.
-
#split! ⇒ void
private
Split the tree at the node.
-
#to_hash ⇒ Hash
private
A hash representation of this node.
Constructor Details
#initialize(document, limit, parent = nil) ⇒ Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Node.
Source Code
36 | def initialize(document, limit, parent = nil) |
37 | @document = document |
38 | @children = [] |
39 | @limit = limit |
40 | @parent = parent |
41 | @ref = nil |
42 | end
|
Instance Attribute Details
#children ⇒ Array<Node> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Child nodes
Source Code
17 | def children |
18 | @children
|
19 | end
|
#document ⇒ Prawn::Document (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Source Code
24 | def document |
25 | @document
|
26 | end
|
#limit ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Children number limit
Source Code
21 | def limit |
22 | @limit
|
23 | end
|
#parent ⇒ Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parent node
Source Code
28 | def parent |
29 | @parent
|
30 | end
|
#ref ⇒ Reference
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Source Code
31 | def ref |
32 | @ref
|
33 | end
|
Instance Method Details
#<<(value) ⇒ value
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Insert value maintaining order and rebalancing tree if needed.
Source Code
110 | def <<(value) |
111 | if children.empty? |
112 | children << value |
113 | elsif leaf? |
114 | children.insert(insertion_point(value), value) |
115 | split! if children.length > limit |
116 | else
|
117 | fit = children.find { |child| child >= value } |
118 | fit ||= children.last |
119 | fit << value |
120 | end
|
121 | |
122 | value
|
123 | end
|
#>=(other) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This is a compatibility method to allow uniform comparison between nodes and values.
Source Code
131 | def >=(other) |
132 | children.empty? || children.last >= other |
133 | end
|
#add(name, value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Adds a value
Source Code
70 | def add(name, value) |
71 | self << Value.new(name, value) |
72 | end
|
#deep_copy ⇒ Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a deep copy of this node, without copying expensive things
like the ref
to document
.
Source Code
153 | def deep_copy |
154 | node = dup |
155 | node.instance_variable_set(:@children, Utils.deep_clone(children)) |
156 | node.instance_variable_set(:@ref, node.ref ? node.ref.deep_copy : nil) |
157 | node
|
158 | end
|
#empty? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Tells whether there are any children nodes
Source Code
47 | def empty? |
48 | children.empty? |
49 | end
|
#greatest ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the greatest (in lexicographic order) value name.
Source Code
98 | def greatest |
99 | if leaf? |
100 | children.last.name |
101 | else
|
102 | children.last.greatest |
103 | end
|
104 | end
|
#leaf? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Tells whether this is a leaf node. A leaf node is the one that has no children or only Value children.
Source Code
62 | def leaf? |
63 | children.empty? || children.first.is_a?(Value) |
64 | end
|
#least ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the least (in lexicographic order) value name.
Source Code
89 | def least |
90 | if leaf? |
91 | children.first.name |
92 | else
|
93 | children.first.least |
94 | end
|
95 | end
|
#size ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Number of all (including nested) children nodes
Source Code
54 | def size |
55 | leaf? ? children.size : children.sum(&:size) |
56 | end
|
#split! ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Split the tree at the node.
Source Code
138 | def split! |
139 | if parent |
140 | parent.split(self) |
141 | else
|
142 | left = new_node(self) |
143 | right = new_node(self) |
144 | split_children(self, left, right) |
145 | children.replace([left, right]) |
146 | end
|
147 | end
|
#to_hash ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a hash representation of this node.
Source Code
75 | def to_hash |
76 | hash = {} |
77 | |
78 | hash[:Limits] = [least, greatest] if parent |
79 | if leaf? |
80 | hash[:Names] = children if leaf? |
81 | else
|
82 | hash[:Kids] = children.map(&:ref) |
83 | end
|
84 | |
85 | hash
|
86 | end
|