class ReVIEW::Book::BookUnit

Attributes

book[R]
column_index[R]
content[RW]
endnote_index[R]
equation_index[R]
footnote_index[R]
headline_index[R]
icon_index[R]
image_index[R]
indepimage_index[R]
lines[R]
list_index[R]
numberless_image_index[R]
path[R]
table_index[R]

Public Class Methods

new(file_content: nil, book: nil) click to toggle source
# File lib/review/book/book_unit.rb, line 26
def initialize(file_content: nil, book: nil)
  if book
    @book = book
  end
  if file_content
    @content = file_content
  end
  if @content
    @lines = @content.lines
  end
end

Public Instance Methods

basename() click to toggle source
# File lib/review/book/book_unit.rb, line 72
def basename
  @path && File.basename(@path)
end
bibpaper(id) click to toggle source
# File lib/review/book/book_unit.rb, line 137
def bibpaper(id)
  bibpaper_index[id]
end
bibpaper_index() click to toggle source
# File lib/review/book/book_unit.rb, line 141
def bibpaper_index
  raise FileNotFound, "no such bib file: #{@book.bib_file}" unless @book.bib_exist?

  @book.bibpaper_index
end
column(id) click to toggle source
# File lib/review/book/book_unit.rb, line 151
def column(id)
  column_index[id]
end
dirname() click to toggle source
# File lib/review/book/book_unit.rb, line 68
def dirname
  @path && File.dirname(@path)
end
endnote(id) click to toggle source
# File lib/review/book/book_unit.rb, line 121
def endnote(id)
  endnote_index[id]
end
endnotes() click to toggle source
# File lib/review/book/book_unit.rb, line 125
def endnotes
  endnote_index
end
equation(id) click to toggle source
# File lib/review/book/book_unit.rb, line 113
def equation(id)
  equation_index[id]
end
execute_indexer(force: false) click to toggle source
# File lib/review/book/book_unit.rb, line 38
def execute_indexer(force: false)
  if @index_builder && !force
    return @index_builder
  end

  @index_builder = ReVIEW::IndexBuilder.new
  compiler = ReVIEW::Compiler.new(@index_builder)
  compiler.compile(self)
  @index_builder
end
footnote(id) click to toggle source
# File lib/review/book/book_unit.rb, line 117
def footnote(id)
  footnote_index[id]
end
generate_indexes(use_bib: false) click to toggle source
# File lib/review/book/book_unit.rb, line 49
def generate_indexes(use_bib: false)
  return unless content

  @lines = content.lines

  @indexes = execute_indexer

  @list_index = @indexes.list_index
  @table_index = @indexes.table_index
  @equation_index = @indexes.equation_index
  @footnote_index = @indexes.footnote_index
  @endnote_index = @indexes.endnote_index
  @headline_index = @indexes.headline_index
  @column_index = @indexes.column_index
  if use_bib
    @book.bibpaper_index = @indexes.bibpaper_index
  end
end
headline(caption) click to toggle source
# File lib/review/book/book_unit.rb, line 147
def headline(caption)
  headline_index[caption]
end
id()
Alias for: name
image(id) click to toggle source
# File lib/review/book/book_unit.rb, line 129
def image(id)
  return image_index[id] if image_index.key?(id)
  return icon_index[id] if icon_index.key?(id)
  return numberless_image_index[id] if numberless_image_index.key?(id)

  indepimage_index[id]
end
image_bound?(item_id) click to toggle source
# File lib/review/book/book_unit.rb, line 163
def image_bound?(item_id)
  image(item_id).path
end
list(id) click to toggle source
# File lib/review/book/book_unit.rb, line 105
def list(id)
  list_index[id]
end
name() click to toggle source
# File lib/review/book/book_unit.rb, line 76
def name
  @name && File.basename(@name, '.*')
end
Also aliased as: id
next_chapter() click to toggle source
# File lib/review/book/book_unit.rb, line 155
def next_chapter
  book.next_chapter(self)
end
prev_chapter() click to toggle source
# File lib/review/book/book_unit.rb, line 159
def prev_chapter
  book.prev_chapter(self)
end
size() click to toggle source
# File lib/review/book/book_unit.rb, line 97
def size
  content.size
end
table(id) click to toggle source
# File lib/review/book/book_unit.rb, line 109
def table(id)
  table_index[id]
end
title() click to toggle source
# File lib/review/book/book_unit.rb, line 82
def title
  return @title if @title

  @title = ''
  return @title unless content

  content.each_line do |line|
    if line =~ /\A=+/
      @title = line.sub(/\A=+(\[.+?\])?(\{.+?\})?/, '').strip
      break
    end
  end
  @title
end
volume() click to toggle source
# File lib/review/book/book_unit.rb, line 101
def volume
  @volume ||= Volume.count_file(path)
end