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.



15
16
17
# File 'lib/review/book/compilable.rb', line 15

def book
  @book
end

#contentObject



73
74
75
# File 'lib/review/book/compilable.rb', line 73

def content
  @content
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#basenameObject



27
28
29
30
# File 'lib/review/book/compilable.rb', line 27

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

#bibpaper(id) ⇒ Object



144
145
146
# File 'lib/review/book/compilable.rb', line 144

def bibpaper(id)
  bibpaper_index[id]
end

#bibpaper_indexObject

Raises:



148
149
150
151
152
# File 'lib/review/book/compilable.rb', line 148

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



162
163
164
# File 'lib/review/book/compilable.rb', line 162

def column(id)
  column_index[id]
end

#column_indexObject



166
167
168
# File 'lib/review/book/compilable.rb', line 166

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

#dirnameObject



22
23
24
25
# File 'lib/review/book/compilable.rb', line 22

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

#envObject



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

def env
  @book
end

#footnote(id) ⇒ Object



100
101
102
# File 'lib/review/book/compilable.rb', line 100

def footnote(id)
  footnote_index[id]
end

#footnote_indexObject



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

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

#headline(caption) ⇒ Object



154
155
156
# File 'lib/review/book/compilable.rb', line 154

def headline(caption)
  headline_index[caption]
end

#headline_indexObject



158
159
160
# File 'lib/review/book/compilable.rb', line 158

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

#icon_indexObject



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

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

#image(id) ⇒ Object



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

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_indexObject



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

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

#indepimage_indexObject



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

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

#linesObject



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

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

#list(id) ⇒ Object



82
83
84
# File 'lib/review/book/compilable.rb', line 82

def list(id)
  list_index[id]
end

#list_indexObject



86
87
88
89
# File 'lib/review/book/compilable.rb', line 86

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

#nameObject Also known as: id



32
33
34
35
# File 'lib/review/book/compilable.rb', line 32

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

#next_chapterObject



170
171
172
# File 'lib/review/book/compilable.rb', line 170

def next_chapter
  book.next_chapter(self)
end

#numberless_image_indexObject



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

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

#open(&_block) ⇒ Object

deprecated; use content()



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

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

#prev_chapterObject



174
175
176
# File 'lib/review/book/compilable.rb', line 174

def prev_chapter
  book.prev_chapter(self)
end

#sizeObject



53
54
55
# File 'lib/review/book/compilable.rb', line 53

def size
  content.size
end

#table(id) ⇒ Object



91
92
93
# File 'lib/review/book/compilable.rb', line 91

def table(id)
  table_index[id]
end

#table_indexObject



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

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

#titleObject



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

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



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

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