Class: ReVIEW::Book::Chapter

Inherits:
Object
  • Object
show all
Includes:
Compilable
Defined in:
lib/review/tocparser.rb,
lib/review/book/chapter.rb

Overview

reopen

Instance Attribute Summary collapse

Attributes included from Compilable

#book, #content, #path

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Compilable

#basename, #bibpaper, #bibpaper_index, #dirname, #env, #footnote, #footnote_index, #headline, #headline_index, #icon_index, #image, #image_index, #indepimage_index, #lines, #list, #list_index, #name, #numberless_image_index, #open, #size, #table, #table_index, #title, #volume

Methods included from TextUtils

#convert_inencoding, #convert_outencoding, #detab, #split_paragraph

Constructor Details

#initialize(book, number, name, path, io = nil) ⇒ Chapter

Returns a new instance of Chapter.



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

def initialize(book, number, name, path, io = nil)
  @book = book
  @number = number
  @name = name
  @path = path
  @io = io
  @title = nil
  @content = nil
  @list_index = nil
  @table_index = nil
  @footnote_index = nil
  @image_index = nil
  @icon_index = nil
  @numberless_image_index = nil
  @indepimage_index = nil
  @headline_index = nil
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



39
40
41
# File 'lib/review/book/chapter.rb', line 39

def number
  @number
end

Class Method Details

.for_path(number, path) ⇒ Object



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

def Chapter.for_path(number, path)
  new(nil, number, File.basename(path), path)
end

.for_stdinObject



31
32
33
# File 'lib/review/book/chapter.rb', line 31

def Chapter.for_stdin
  new(nil, nil, '-', nil, $stdin)
end

.intern_pathes(pathes) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/review/book/chapter.rb', line 18

def Chapter.intern_pathes(pathes)
  books = {}
  pathes.map {|path|
    basedir = File.dirname(path)
    book = (books[File.expand_path(basedir)] ||= Book.load(basedir))
    begin
      book.chapter(File.basename(path, '.*'))
    rescue KeyError => err
      raise FileNotFound, "no such file: #{path}"
    end
  }
end

Instance Method Details

#inspectObject



59
60
61
# File 'lib/review/book/chapter.rb', line 59

def inspect
  "\#<#{self.class} #{@number} #{@path}>"
end

#on_CHAPS?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/review/book/chapter.rb', line 63

def on_CHAPS?
  on_FILE?(@book.read_CHAPS())
end

#on_POSTDEF?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/review/book/chapter.rb', line 71

def on_POSTDEF?
  on_FILE?(@book.read_POSTDEF())
end

#on_PREDEF?Boolean

Returns:

  • (Boolean)


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

def on_PREDEF?
  on_FILE?(@book.read_PREDEF())
end

#tocObject



334
335
336
337
338
339
340
# File 'lib/review/tocparser.rb', line 334

def toc
  @toc ||= TOCParser.parse(self)
  unless @toc.size == 1
    $stderr.puts "warning: chapter #{@toc.join} contains more than 1 chapter"
  end
  @toc.first
end