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

#content, #path

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

#detab, #split_paragraph

Constructor Details

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

Returns a new instance of Chapter.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/review/book/chapter.rb', line 23

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

#bookObject (readonly)

Returns the value of attribute book.



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

def book
  @book
end

#numberObject (readonly)

Returns the value of attribute number.



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

def number
  @number
end

Instance Method Details

#format_number(heading = true) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/review/book/chapter.rb', line 46

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

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

    type = @book.config["appendix_format"].blank? ? "arabic" : @book.config["appendix_format"].downcase.strip
    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



42
43
44
# File 'lib/review/book/chapter.rb', line 42

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

#on_APPENDIX?Boolean

Returns:

  • (Boolean)


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

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

#on_CHAPS?Boolean

Returns:

  • (Boolean)


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

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

#on_POSTDEF?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/review/book/chapter.rb', line 90

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

#on_PREDEF?Boolean

Returns:

  • (Boolean)


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

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

#tocObject



339
340
341
342
343
344
345
# File 'lib/review/tocparser.rb', line 339

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