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, 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, #index, #inspect, #next_siblings, #prev_siblings, #siblings, #text_, #to_s
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_siblings, #_lookup_siblings, #_matches?, #has_parent?, #lookup, #lookup_children, #lookup_next_siblings, #lookup_parents, #lookup_prev_siblings, #lookup_siblings, #matches?
Constructor Details
Instance Attribute Details
#children ⇒ Nodes (readonly)
List of children
15 16 17 |
# File 'lib/infoboxer/tree/compound.rb', line 15 def children @children end |
Instance Method Details
#index_of(child) ⇒ Fixnum
Index of provided node in children list
20 21 22 |
# File 'lib/infoboxer/tree/compound.rb', line 20 def index_of(child) children.index(child) end |
#text ⇒ Object
See Node#text
33 34 35 |
# File 'lib/infoboxer/tree/compound.rb', line 33 def text children.map(&:text).join(children_separator) end |
#to_tree(level = 0) ⇒ Object
See Node#to_tree
38 39 40 41 42 43 44 45 |
# File 'lib/infoboxer/tree/compound.rb', line 38 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(&call(to_tree: level+1)).join end end |