Class: ReVIEW::Book::HeadlineIndex
- Defined in:
- lib/review/book/index.rb
Defined Under Namespace
Classes: Item
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(items, chap) ⇒ HeadlineIndex
constructor
A new instance of HeadlineIndex.
- #number(id) ⇒ Object
Methods inherited from Index
#[], #each, #has_key?, item_class, #item_type
Constructor Details
#initialize(items, chap) ⇒ HeadlineIndex
Returns a new instance of HeadlineIndex.
324 325 326 327 328 329 330 331 332 |
# File 'lib/review/book/index.rb', line 324 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 |
Class Method Details
.parse(src, chap) ⇒ Object
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/review/book/index.rb', line 299 def HeadlineIndex.parse(src, chap) items = [] indexs = [] headlines = [] src.each do |line| if m = /\A(=+)(?:\[(.+?)\])?(?:\{(.+?)\})?(.*)/.match(line) next if m[2] == 'column' index = m[1].size - 2 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[4].strip items.push Item.new(headlines.join("|"), indexs.dup, m[4].strip) end end end new(items, chap) end |
Instance Method Details
#number(id) ⇒ Object
334 335 336 |
# File 'lib/review/book/index.rb', line 334 def number(id) return ([@chap.number] + @index.fetch(id).number).join(".") end |