Class: ReVIEW::Book::HeadlineIndex

Inherits:
Index show all
Defined in:
lib/review/book/index.rb

Constant Summary collapse

HEADLINE_PATTERN =
/\A(=+)(?:\[(.+?)\])?(?:\{(.+?)\})?(.*)/

Instance Method Summary collapse

Methods inherited from Index

#[], #add_item, #each, #item_type, #key?, #size

Constructor Details

#initialize(chapter) ⇒ HeadlineIndex

Returns a new instance of HeadlineIndex.



178
179
180
181
# File 'lib/review/book/index.rb', line 178

def initialize(chapter)
  super()
  @chapter = chapter
end

Instance Method Details

#number(id) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/review/book/index.rb', line 183

def number(id)
  unless self[id].number
    # when notoc
    return ''
  end

  n = @chapter.number
  # XXX: remove magic number (move to lib/review/book/chapter.rb)
  if @chapter.on_appendix? && @chapter.number > 0 && @chapter.number < 28
    n = @chapter.format_number(false)
  end
  ([n] + self[id].number).join('.')
end