Class: ReVIEW::Book::Chapter

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

Overview

reopen

Constant Summary collapse

ROMAN =
%w[0 I II III IV V VI VII VIII IX X XI XII XIII XIV XV XVI XVII XVIII XIX XX XXI XXII XXIII XXIV XXV XXVI XXVII]
ALPHA =
%w[0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z]

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, #column, #column_index, #dirname, #env, #footnote, #footnote_index, #headline, #headline_index, #icon_index, #image, #image_index, #indepimage_index, #lines, #list, #list_index, #name, #next_chapter, #numberless_image_index, #open, #prev_chapter, #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.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/review/book/chapter.rb', line 36

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
  @column_index = nil
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



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

def number
  @number
end

Class Method Details

.intern_pathes(pathes) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/review/book/chapter.rb', line 21

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
      raise FileNotFound, "No such chapter in your book. Check if the catalog files contain the chapter. : #{path}"
    end
  }
end

Instance Method Details

#format_number(heading = true) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/review/book/chapter.rb', line 59

def format_number(heading = true)
  if on_PREDEF?
    return "#{@number}"
  end

  if on_APPENDIX?
    return "#{@number}" if @number < 1 || @number > 27

    if @book.config["appendix_format"].blank?
      type = "arabic"
    else
      type = @book.config["appendix_format"].downcase.strip
    end

    appendix = case type
                 when "roman"
                   ROMAN[@number]
                 when "alphabet", "alpha"
                   ALPHA[@number]
                 else
                   # nil, "arabic", etc...
                   "#{@number}"
               end

    if heading
      return "#{I18n.t("appendix", appendix)}"
    else
      return "#{appendix}"
    end
  end

  if heading
    "#{I18n.t("chapter", @number)}"
  else
    "#{@number}"
  end
end

#inspectObject



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

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

#on_APPENDIX?Boolean

Returns:

  • (Boolean)


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

def on_APPENDIX?
  on_FILE?(@book.read_APPENDIX)
end

#on_CHAPS?Boolean

Returns:

  • (Boolean)


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

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

#on_POSTDEF?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/review/book/chapter.rb', line 109

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

#on_PREDEF?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/review/book/chapter.rb', line 101

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

#tocObject



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

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