Class: ReVIEW::TOCParser::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/review/tocparser.rb

Direct Known Subclasses

List, Paragraph, Section

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(children = []) ⇒ Node

Returns a new instance of Node.



120
121
122
# File 'lib/review/tocparser.rb', line 120

def initialize(children = [])
  @children = children
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



124
125
126
# File 'lib/review/tocparser.rb', line 124

def children
  @children
end

Instance Method Details

#add_child(c) ⇒ Object



126
127
128
# File 'lib/review/tocparser.rb', line 126

def add_child(c)
  @children.push c
end

#chapter?Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/review/tocparser.rb', line 141

def chapter?
  false
end

#each_child(&block) ⇒ Object



137
138
139
# File 'lib/review/tocparser.rb', line 137

def each_child(&block)
  @children.each(&block)
end

#each_node(&block) ⇒ Object



130
131
132
133
134
135
# File 'lib/review/tocparser.rb', line 130

def each_node(&block)
  @children.each do |c|
    yield c
    c.each(&block)
  end
end

#each_section(&block) ⇒ Object



145
146
147
# File 'lib/review/tocparser.rb', line 145

def each_section(&block)
  @children.each { |n| n.yield_section(&block) }
end

#each_section_with_indexObject



149
150
151
152
153
154
155
# File 'lib/review/tocparser.rb', line 149

def each_section_with_index
  i = 0
  each_section do |n|
    yield n, i
    i += 1
  end
end

#section_sizeObject



157
158
159
160
161
# File 'lib/review/tocparser.rb', line 157

def section_size
  cnt = 0
  @children.each { |n| n.yield_section { cnt += 1 } }
  cnt
end