Class: ReVIEW::TOCParser::Node
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
Instance Method Summary collapse
- #add_child(c) ⇒ Object
- #chapter? ⇒ Boolean
- #each_child(&block) ⇒ Object
- #each_node(&block) ⇒ Object
- #each_section(&block) ⇒ Object
- #each_section_with_index ⇒ Object
-
#initialize(children = []) ⇒ Node
constructor
A new instance of Node.
- #n_sections ⇒ Object
Constructor Details
#initialize(children = []) ⇒ Node
113 114 115 |
# File 'lib/review/tocparser.rb', line 113 def initialize(children = []) @children = children end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
117 118 119 |
# File 'lib/review/tocparser.rb', line 117 def children @children end |
Instance Method Details
#add_child(c) ⇒ Object
119 120 121 |
# File 'lib/review/tocparser.rb', line 119 def add_child(c) @children.push c end |
#chapter? ⇒ Boolean
134 135 136 |
# File 'lib/review/tocparser.rb', line 134 def chapter? false end |
#each_child(&block) ⇒ Object
130 131 132 |
# File 'lib/review/tocparser.rb', line 130 def each_child(&block) @children.each(&block) end |
#each_node(&block) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/review/tocparser.rb', line 123 def each_node(&block) @children.each do |c| yield c c.each(&block) end end |
#each_section(&block) ⇒ Object
138 139 140 141 142 |
# File 'lib/review/tocparser.rb', line 138 def each_section(&block) @children.each do |n| n.yield_section(&block) end end |
#each_section_with_index ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/review/tocparser.rb', line 144 def each_section_with_index i = 0 each_section do |n| yield n, i i += 1 end end |
#n_sections ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/review/tocparser.rb', line 152 def n_sections cnt = 0 @children.each do |n| n.yield_section { cnt += 1 } end cnt end |