Class: Infoboxer::Tree::Compound

Inherits:
Node
  • Object
show all
Defined in:
lib/infoboxer/tree/compound.rb

Overview

Base class for all nodes with children.

Instance Attribute Summary collapse

Attributes inherited from Node

#params, #parent

Instance Method Summary collapse

Methods inherited from Node

#==, coder, def_readers, #first?, #index, #inspect, #next_siblings, #prev_siblings, #siblings, #text_, #to_s

Methods included from Navigation::Wikipath

#wikipath

Methods included from Navigation::Sections::Node

#in_sections

Methods included from Navigation::Shortcuts::Node

#bold?, #categories, #external_links, #heading?, #headings, #images, #infobox, #infoboxes, #italic?, #lists, #paragraphs, #tables, #templates, #wikilinks

Methods included from Navigation::Lookup::Node

#_lookup, #_lookup_children, #_lookup_next_siblings, #_lookup_parents, #_lookup_prev_sibling, #_lookup_prev_siblings, #_lookup_siblings, #_matches?, #lookup, #lookup_children, #lookup_next_siblings, #lookup_parents, #lookup_prev_sibling, #lookup_prev_siblings, #lookup_siblings, #matches?, #parent?

Constructor Details

#initialize(children = Nodes.new, **params) ⇒ Compound

Returns a new instance of Compound.



5
6
7
8
9
# File 'lib/infoboxer/tree/compound.rb', line 5

def initialize(children = Nodes.new, **params)
  super(params)
  @children = Nodes[*children]
  @children.each { |c| c.parent = self }
end

Instance Attribute Details

#childrenNodes (readonly)

List of children

Returns:



14
15
16
# File 'lib/infoboxer/tree/compound.rb', line 14

def children
  @children
end

Instance Method Details

#index_of(child) ⇒ Fixnum

Index of provided node in children list

Returns:

  • (Fixnum)

    or nil if not a child



19
20
21
# File 'lib/infoboxer/tree/compound.rb', line 19

def index_of(child)
  children.index(child)
end

#textObject

See Node#text



32
33
34
# File 'lib/infoboxer/tree/compound.rb', line 32

def text
  children.map(&:text).join(children_separator)
end

#to_tree(level = 0) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/infoboxer/tree/compound.rb', line 37

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