Class: Infoboxer::Tree::Compound
- Defined in:
- lib/infoboxer/tree/compound.rb
Overview
Base class for all nodes with children.
Direct Known Subclasses
Navigation::Sections::Section, BaseCell, BaseParagraph, Bold, BoldItalic, Document, Gallery, HTMLTag, ImageCaption, Italic, Link, List, Ref, Table, TableCaption, TableRow, Template, Var
Instance Attribute Summary collapse
-
#children ⇒ Nodes
readonly
List of children.
Attributes inherited from Node
Instance Method Summary collapse
-
#index_of(child) ⇒ Fixnum
Index of provided node in children list.
-
#initialize(children = Nodes.new, **params) ⇒ Compound
constructor
A new instance of Compound.
-
#text ⇒ Object
See Node#text.
-
#to_tree(level = 0) ⇒ Object
See Node#to_tree.
Methods inherited from Node
#==, coder, def_readers, #first?, #index, #inspect, #next_siblings, #prev_siblings, #siblings, #text_, #to_s
Methods included from Navigation::Wikipath
Methods included from Navigation::Sections::Node
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
Instance Attribute Details
#children ⇒ Nodes (readonly)
List of children
16 17 18 |
# File 'lib/infoboxer/tree/compound.rb', line 16 def children @children end |
Instance Method Details
#index_of(child) ⇒ Fixnum
Index of provided node in children list
21 22 23 |
# File 'lib/infoboxer/tree/compound.rb', line 21 def index_of(child) children.index(child) end |
#text ⇒ Object
See Node#text
34 35 36 |
# File 'lib/infoboxer/tree/compound.rb', line 34 def text children.map(&:text).join(children_separator) end |
#to_tree(level = 0) ⇒ Object
See Node#to_tree
39 40 41 42 43 44 45 |
# 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 |