Class: ReVIEW::Book::ChapterIndex

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

Instance Method Summary collapse

Methods inherited from Index

#[], #each, #has_key?, #initialize, item_class, parse

Constructor Details

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

Instance Method Details

#display_string(id) ⇒ Object



110
111
112
# File 'lib/review/book/index.rb', line 110

def display_string(id)
  "#{number(id)}#{I18n.t("chapter_quote", title(id))}"
end

#item_typeObject



89
90
91
# File 'lib/review/book/index.rb', line 89

def item_type
  'chapter'
end

#number(id) ⇒ Object



93
94
95
96
97
98
99
100
101
102
# File 'lib/review/book/index.rb', line 93

def number(id)
  chapter = @index.fetch(id, nil)
  if chapter
    return chapter.format_number
  else
    return "#{I18n.t("part", chapter.number)}"
  end
rescue # part
  raise "invalid number error: id:#{id}, capter:#{chapter}"
end

#title(id) ⇒ Object



104
105
106
107
108
# File 'lib/review/book/index.rb', line 104

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