Module: ReVIEW::Book::Compilable

Includes:
TextUtils
Included in:
Chapter, Part
Defined in:
lib/review/book/compilable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TextUtils

#detab, #split_paragraph

Instance Attribute Details

#bookObject (readonly)

Returns the value of attribute book.



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

def book
  @book
end

#contentObject



75
76
77
# File 'lib/review/book/compilable.rb', line 75

def content
  @content
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#basenameObject



29
30
31
32
# File 'lib/review/book/compilable.rb', line 29

def basename
  return nil unless @path
  File.basename(@path)
end

#bibpaper(id) ⇒ Object



146
147
148
# File 'lib/review/book/compilable.rb', line 146

def bibpaper(id)
  bibpaper_index()[id]
end

#bibpaper_indexObject

Raises:



150
151
152
153
154
# File 'lib/review/book/compilable.rb', line 150

def bibpaper_index
  raise FileNotFound, "no such bib file: #{@book.bib_file}" unless @book.bib_exist?
  @bibpaper_index ||= BibpaperIndex.parse(@book.read_bib.lines.to_a)
  @bibpaper_index
end

#column(id) ⇒ Object



164
165
166
# File 'lib/review/book/compilable.rb', line 164

def column(id)
  column_index()[id]
end

#column_indexObject



168
169
170
# File 'lib/review/book/compilable.rb', line 168

def column_index
  @column_index ||= ColumnIndex.parse(lines())
end

#dirnameObject



24
25
26
27
# File 'lib/review/book/compilable.rb', line 24

def dirname
  return nil unless @path
  File.dirname(@path)
end

#envObject



20
21
22
# File 'lib/review/book/compilable.rb', line 20

def env
  @book
end

#footnote(id) ⇒ Object



102
103
104
# File 'lib/review/book/compilable.rb', line 102

def footnote(id)
  footnote_index()[id]
end

#footnote_indexObject



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

def footnote_index
  @footnote_index ||= FootnoteIndex.parse(lines())
  @footnote_index
end

#headline(caption) ⇒ Object



156
157
158
# File 'lib/review/book/compilable.rb', line 156

def headline(caption)
  headline_index()[caption]
end

#headline_indexObject



160
161
162
# File 'lib/review/book/compilable.rb', line 160

def headline_index
  @headline_index ||= HeadlineIndex.parse(lines(), self)
end

#icon_indexObject



132
133
134
135
136
137
# File 'lib/review/book/compilable.rb', line 132

def icon_index
  @icon_index ||= IconIndex.parse(lines(), id(),
    "#{book.basedir}/#{@book.image_dir}",
    @book.image_types, @book.config['builder'])
  @icon_index
end

#image(id) ⇒ Object



111
112
113
114
115
116
# File 'lib/review/book/compilable.rb', line 111

def image(id)
  return image_index()[id] if image_index().has_key?(id)
  return icon_index()[id] if icon_index().has_key?(id)
  return numberless_image_index()[id] if numberless_image_index().has_key?(id)
  indepimage_index()[id]
end

#image_indexObject



125
126
127
128
129
130
# File 'lib/review/book/compilable.rb', line 125

def image_index
  @image_index ||= ImageIndex.parse(lines(), id(),
    "#{book.basedir}/#{@book.image_dir}",
    @book.image_types, @book.config['builder'])
  @image_index
end

#indepimage_indexObject



139
140
141
142
143
144
# File 'lib/review/book/compilable.rb', line 139

def indepimage_index
  @indepimage_index ||=
    IndepImageIndex.parse(lines(), id(),
    "#{book.basedir}/#{@book.image_dir}",
    @book.image_types, @book.config['builder'])
end

#linesObject



79
80
81
82
# File 'lib/review/book/compilable.rb', line 79

def lines
  # FIXME: we cannot duplicate Enumerator on ruby 1.9 HEAD
  (@lines ||= content().lines.to_a).dup
end

#list(id) ⇒ Object



84
85
86
# File 'lib/review/book/compilable.rb', line 84

def list(id)
  list_index()[id]
end

#list_indexObject



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

def list_index
  @list_index ||= ListIndex.parse(lines())
  @list_index
end

#nameObject Also known as: id



34
35
36
37
# File 'lib/review/book/compilable.rb', line 34

def name
  return nil unless @name
  File.basename(@name, '.*')
end

#next_chapterObject



172
173
174
# File 'lib/review/book/compilable.rb', line 172

def next_chapter
  book.next_chapter(self)
end

#numberless_image_indexObject



118
119
120
121
122
123
# File 'lib/review/book/compilable.rb', line 118

def numberless_image_index
  @numberless_image_index ||=
    NumberlessImageIndex.parse(lines(), id(),
    "#{book.basedir}/#{@book.image_dir}",
    @book.image_types, @book.config['builder'])
end

#open(&block) ⇒ Object

deprecated; use content()



68
69
70
71
# File 'lib/review/book/compilable.rb', line 68

def open(&block)
  return (block_given?() ? yield(@io) : @io) if @io
  StringIO.new(content)
end

#prev_chapterObject



176
177
178
# File 'lib/review/book/compilable.rb', line 176

def prev_chapter
  book.prev_chapter(self)
end

#sizeObject



55
56
57
# File 'lib/review/book/compilable.rb', line 55

def size
  content.size
end

#table(id) ⇒ Object



93
94
95
# File 'lib/review/book/compilable.rb', line 93

def table(id)
  table_index()[id]
end

#table_indexObject



97
98
99
100
# File 'lib/review/book/compilable.rb', line 97

def table_index
  @table_index ||= TableIndex.parse(lines())
  @table_index
end

#titleObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/review/book/compilable.rb', line 41

def title
  return @title if @title

  @title = ''
  return @title if !content
  content.each_line do |line|
    if line =~ /\A=+/
      @title = line.sub(/\A=+(\[.+?\])?(\{.+?\})?/, '').strip
      break
    end
  end
  @title
end

#volumeObject



59
60
61
62
63
64
65
# File 'lib/review/book/compilable.rb', line 59

def volume
  if !@volume
    @volume = Volume.count_file(path())
    @volume.page_per_kbyte = @book.page_metric.page_per_kbyte
  end
  @volume
end