class Infoboxer::Tree::Compound
Base class for all nodes with children.
Attributes
children[R]
List
of children
@return {Nodes}
Public Class Methods
new(children = Nodes.new, **params)
click to toggle source
Calls superclass method
# File lib/infoboxer/tree/compound.rb, line 7 def initialize(children = Nodes.new, **params) super(**params) @children = Nodes[*children] @children.each { |c| c.parent = self } end
Public Instance Methods
can_merge?(_other)
click to toggle source
@private Internal, used by {Parser}
# File lib/infoboxer/tree/compound.rb, line 51 def can_merge?(_other) false end
closed!()
click to toggle source
@private Internal, used by {Parser}
# File lib/infoboxer/tree/compound.rb, line 57 def closed! @closed = true end
closed?()
click to toggle source
@private Internal, used by {Parser}
# File lib/infoboxer/tree/compound.rb, line 63 def closed? @closed end
empty?()
click to toggle source
@private Internal, used by {Parser}
# File lib/infoboxer/tree/compound.rb, line 69 def empty? children.empty? end
index_of(child)
click to toggle source
Index of provided node in children list
@return [Fixnum] or `nil` if not a child
# File lib/infoboxer/tree/compound.rb, line 21 def index_of(child) children.index(child) end
push_children(*nodes)
click to toggle source
@private Internal, used by {Parser}
# File lib/infoboxer/tree/compound.rb, line 27 def push_children(*nodes) nodes.each { |c| c.parent = self }.each do |n| @children << n end end
text()
click to toggle source
See {Node#text}
# File lib/infoboxer/tree/compound.rb, line 34 def text children.map(&:text).join(children_separator) end
to_tree(level = 0)
click to toggle source
See {Node#to_tree}
# File lib/infoboxer/tree/compound.rb, line 39 def to_tree(level = 0) if children.count == 1 && children.first.is_a?(Text) "#{indent(level)}#{children.first.text} <#{descr}>\n" else "#{indent(level)}<#{descr}>\n" + children.map { |c| c.to_tree(level + 1) }.join end end
Protected Instance Methods
children_separator()
click to toggle source
# File lib/infoboxer/tree/compound.rb, line 75 def children_separator '' end
Private Instance Methods
_eq(other)
click to toggle source
# File lib/infoboxer/tree/compound.rb, line 81 def _eq(other) children == other.children end