Class: ReVIEW::Book::Part

Inherits:
BookUnit show all
Defined in:
lib/review/book/part.rb

Instance Attribute Summary collapse

Attributes inherited from BookUnit

#book, #column_index, #content, #endnote_index, #equation_index, #footnote_index, #headline_index, #icon_index, #image_index, #indepimage_index, #lines, #list_index, #numberless_image_index, #path, #table_index

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BookUnit

#basename, #bibpaper, #bibpaper_index, #column, #dirname, #endnote, #endnotes, #equation, #execute_indexer, #footnote, #headline, #image, #image_bound?, #list, #next_chapter, #prev_chapter, #size, #table, #title

Methods included from TextUtils

#add_space?, #detab, #join_lines_to_paragraph, #split_paragraph

Constructor Details

#initialize(book, number, chapters, name = '', io = nil) ⇒ Part

if Part is dummy, ‘number` is nil.



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

def initialize(book, number, chapters, name = '', io = nil)
  @book = book
  @number = number
  @name = name
  @chapters = chapters
  @path = name
  if io
    @content = io.read
  elsif @path.present? && File.exist?(File.join(@book.config['contentdir'], @path))
    @content = File.read(File.join(@book.config['contentdir'], @path), mode: 'rt:BOM|utf-8')
    @name = File.basename(name, '.re')
  else
    @content = ''
  end
  @title = if file?
             nil
           else
             name
           end
  @volume = nil

  super()
end

Instance Attribute Details

#chaptersObject (readonly)

Returns the value of attribute chapters.



72
73
74
# File 'lib/review/book/part.rb', line 72

def chapters
  @chapters
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#numberObject (readonly)

Returns the value of attribute number.



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

def number
  @number
end

Class Method Details

.mkpart(chaps) ⇒ Object



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

def self.mkpart(chaps)
  chaps.empty? ? nil : Part.new(chaps[0].book, nil, chaps)
end

.mkpart_from_namelist(book, names) ⇒ Object



26
27
28
# File 'lib/review/book/part.rb', line 26

def self.mkpart_from_namelist(book, names)
  Part.mkpart(names.map { |name| Chapter.mkchap_ifexist(book, name) }.compact)
end

.mkpart_from_namelistfile(book, path) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/review/book/part.rb', line 14

def self.mkpart_from_namelistfile(book, path)
  chaps = []
  File.read(path, mode: 'rt:BOM|utf-8').split.each_with_index do |name, number|
    chaps << if /PREDEF/.match?(path)
               Chapter.mkchap(book, name)
             else
               Chapter.mkchap(book, name, number + 1)
             end
  end
  Part.mkpart(chaps)
end

Instance Method Details

#each_chapter(&block) ⇒ Object



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

def each_chapter(&block)
  @chapters.each(&block)
end

#file?Boolean

Returns:

  • (Boolean)


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

def file?
  name.present? and path.end_with?('.re')
end

#format_number(heading = true) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/review/book/part.rb', line 91

def format_number(heading = true)
  if heading
    I18n.t('part', @number)
  else
    @number.to_s
  end
end

#generate_indexesObject



60
61
62
63
64
65
66
67
68
69
# File 'lib/review/book/part.rb', line 60

def generate_indexes
  super

  return unless content

  @numberless_image_index = @indexes.numberless_image_index
  @image_index = @indexes.image_index
  @icon_index = @indexes.icon_index
  @indepimage_index = @indexes.indepimage_index
end

#on_appendix?Boolean Also known as: on_APPENDIX?

Returns:

  • (Boolean)


99
100
101
# File 'lib/review/book/part.rb', line 99

def on_appendix?
  false
end

#volumeObject



79
80
81
82
83
84
85
# File 'lib/review/book/part.rb', line 79

def volume
  if @number && file?
    Volume.count_file(File.join(@book.config['contentdir'], @path))
  else
    Volume.new(0, 0, 0)
  end
end