class ReVIEW::Book::HeadlineIndex
Constants
- HEADLINE_PATTERN
- Item
Attributes
items[R]
Public Class Methods
new(items, chap)
click to toggle source
# File lib/review/book/index.rb, line 333 def initialize(items, chap) @items = items @chap = chap @index = {} items.each do |i| warn "warning: duplicate ID: #{i.id}" unless @index[i.id].nil? @index[i.id] = i end end
parse(src, chap)
click to toggle source
# File lib/review/book/index.rb, line 290 def HeadlineIndex.parse(src, chap) items = [] indexs = [] headlines = [] inside_column = false src.each do |line| if m = HEADLINE_PATTERN.match(line) next if m[1].size > 10 # Ignore too deep index index = m[1].size - 2 # column if m[2] == 'column' inside_column = true next end if m[2] == '/column' inside_column = false next end if indexs.blank? || index <= indexs[-1] inside_column = false end if inside_column next end if index >= 0 if indexs.size > (index + 1) indexs = indexs.take(index + 1) headlines = headlines.take(index + 1) end if indexs[index].nil? (0..index).each{|i| indexs[i] = 0 if indexs[i].nil?} end indexs[index] += 1 headlines[index] = m[3].present? ? m[3].strip : m[4].strip items.push Item.new(headlines.join("|"), indexs.dup, m[4].strip) end end end new(items, chap) end
Public Instance Methods
number(id)
click to toggle source
# File lib/review/book/index.rb, line 343 def number(id) n = @chap.number if @chap.on_APPENDIX? && @chap.number > 0 && @chap.number < 28 n = @chap.format_number(false) end return ([n] + self[id].number).join(".") end