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.



112
113
114
# File 'lib/review/tocparser.rb', line 112

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

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



116
117
118
# File 'lib/review/tocparser.rb', line 116

def children
  @children
end

Instance Method Details

#add_child(c) ⇒ Object



118
119
120
# File 'lib/review/tocparser.rb', line 118

def add_child(c)
  @children.push c
end

#chapter?Boolean

Returns:

  • (Boolean)


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

def chapter?
  false
end

#each_child(&block) ⇒ Object



129
130
131
# File 'lib/review/tocparser.rb', line 129

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

#each_node(&block) ⇒ Object



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

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

#each_section(&block) ⇒ Object



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

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

#each_section_with_indexObject



143
144
145
146
147
148
149
# File 'lib/review/tocparser.rb', line 143

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

#n_sectionsObject



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

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