Class: ReVIEW::Book::BookUnit

Inherits:
Object
  • Object
show all
Includes:
TextUtils
Defined in:
lib/review/book/book_unit.rb

Direct Known Subclasses

Bib, Chapter, Part

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TextUtils

#add_space?, #detab, #join_lines_to_paragraph, #split_paragraph

Constructor Details

#initialize(file_content: nil, book: nil) ⇒ BookUnit

Returns a new instance of BookUnit.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/review/book/book_unit.rb', line 25

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

Instance Attribute Details

#bookObject (readonly)

Returns the value of attribute book.



16
17
18
# File 'lib/review/book/book_unit.rb', line 16

def book
  @book
end

#column_indexObject (readonly)

Returns the value of attribute column_index.



21
22
23
# File 'lib/review/book/book_unit.rb', line 21

def column_index
  @column_index
end

#contentObject

Returns the value of attribute content.



19
20
21
# File 'lib/review/book/book_unit.rb', line 19

def content
  @content
end

#equation_indexObject (readonly)

Returns the value of attribute equation_index.



21
22
23
# File 'lib/review/book/book_unit.rb', line 21

def equation_index
  @equation_index
end

#footnote_indexObject (readonly)

Returns the value of attribute footnote_index.



21
22
23
# File 'lib/review/book/book_unit.rb', line 21

def footnote_index
  @footnote_index
end

#headline_indexObject (readonly)

Returns the value of attribute headline_index.



21
22
23
# File 'lib/review/book/book_unit.rb', line 21

def headline_index
  @headline_index
end

#icon_indexObject (readonly)

Returns the value of attribute icon_index.



21
22
23
# File 'lib/review/book/book_unit.rb', line 21

def icon_index
  @icon_index
end

#image_indexObject (readonly)

Returns the value of attribute image_index.



21
22
23
# File 'lib/review/book/book_unit.rb', line 21

def image_index
  @image_index
end

#indepimage_indexObject (readonly)

Returns the value of attribute indepimage_index.



21
22
23
# File 'lib/review/book/book_unit.rb', line 21

def indepimage_index
  @indepimage_index
end

#linesObject (readonly)

Returns the value of attribute lines.



18
19
20
# File 'lib/review/book/book_unit.rb', line 18

def lines
  @lines
end

#list_indexObject (readonly)

Returns the value of attribute list_index.



21
22
23
# File 'lib/review/book/book_unit.rb', line 21

def list_index
  @list_index
end

#numberless_image_indexObject (readonly)

Returns the value of attribute numberless_image_index.



21
22
23
# File 'lib/review/book/book_unit.rb', line 21

def numberless_image_index
  @numberless_image_index
end

#pathObject (readonly)

Returns the value of attribute path.



17
18
19
# File 'lib/review/book/book_unit.rb', line 17

def path
  @path
end

#table_indexObject (readonly)

Returns the value of attribute table_index.



21
22
23
# File 'lib/review/book/book_unit.rb', line 21

def table_index
  @table_index
end

Instance Method Details

#basenameObject



70
71
72
# File 'lib/review/book/book_unit.rb', line 70

def basename
  @path && File.basename(@path)
end

#bibpaper(id) ⇒ Object



127
128
129
# File 'lib/review/book/book_unit.rb', line 127

def bibpaper(id)
  bibpaper_index[id]
end

#bibpaper_indexObject

Raises:



131
132
133
134
135
# File 'lib/review/book/book_unit.rb', line 131

def bibpaper_index
  raise FileNotFound, "no such bib file: #{@book.bib_file}" unless @book.bib_exist?

  @book.bibpaper_index
end

#column(id) ⇒ Object



141
142
143
# File 'lib/review/book/book_unit.rb', line 141

def column(id)
  column_index[id]
end

#dirnameObject



66
67
68
# File 'lib/review/book/book_unit.rb', line 66

def dirname
  @path && File.dirname(@path)
end

#equation(id) ⇒ Object



111
112
113
# File 'lib/review/book/book_unit.rb', line 111

def equation(id)
  equation_index[id]
end

#execute_indexer(force: false) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/review/book/book_unit.rb', line 37

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) ⇒ Object



115
116
117
# File 'lib/review/book/book_unit.rb', line 115

def footnote(id)
  footnote_index[id]
end

#generate_indexes(use_bib: false) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/review/book/book_unit.rb', line 48

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
  @headline_index = @indexes.headline_index
  @column_index = @indexes.column_index
  if use_bib
    @book.bibpaper_index = @indexes.bibpaper_index
  end
end

#headline(caption) ⇒ Object



137
138
139
# File 'lib/review/book/book_unit.rb', line 137

def headline(caption)
  headline_index[caption]
end

#image(id) ⇒ Object



119
120
121
122
123
124
125
# File 'lib/review/book/book_unit.rb', line 119

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) ⇒ Boolean

Returns:

  • (Boolean)


153
154
155
# File 'lib/review/book/book_unit.rb', line 153

def image_bound?(item_id)
  image(item_id).path
end

#list(id) ⇒ Object



103
104
105
# File 'lib/review/book/book_unit.rb', line 103

def list(id)
  list_index[id]
end

#nameObject Also known as: id



74
75
76
# File 'lib/review/book/book_unit.rb', line 74

def name
  @name && File.basename(@name, '.*')
end

#next_chapterObject



145
146
147
# File 'lib/review/book/book_unit.rb', line 145

def next_chapter
  book.next_chapter(self)
end

#prev_chapterObject



149
150
151
# File 'lib/review/book/book_unit.rb', line 149

def prev_chapter
  book.prev_chapter(self)
end

#sizeObject



95
96
97
# File 'lib/review/book/book_unit.rb', line 95

def size
  content.size
end

#table(id) ⇒ Object



107
108
109
# File 'lib/review/book/book_unit.rb', line 107

def table(id)
  table_index[id]
end

#titleObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/review/book/book_unit.rb', line 80

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

#volumeObject



99
100
101
# File 'lib/review/book/book_unit.rb', line 99

def volume
  @volume ||= Volume.count_file(path)
end