Class: ReVIEW::Book::ChapterIndex

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

Instance Method Summary collapse

Methods inherited from Index

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

Constructor Details

This class inherits a constructor from ReVIEW::Book::Index

Instance Method Details

#display_string(id) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/review/book/index.rb', line 98

def display_string(id)
  if number(id)
    I18n.t('chapter_quote', [number(id), title(id)])
  else
    I18n.t('chapter_quote_without_number', title(id))
  end
end

#item_typeObject



78
79
80
# File 'lib/review/book/index.rb', line 78

def item_type
  'chapter'
end

#number(id) ⇒ Object



82
83
84
85
86
87
88
89
90
# File 'lib/review/book/index.rb', line 82

def number(id)
  chapter_item = @index.fetch(id)
  begin
    chapter = chapter_item.content
    chapter.format_number
  rescue # part
    I18n.t('part', chapter.number)
  end
end

#title(id) ⇒ Object



92
93
94
95
96
# File 'lib/review/book/index.rb', line 92

def title(id)
  @index.fetch(id).content.title
rescue # non-file part
  @index.fetch(id).content.name
end