Class: ReVIEW::Book::Part
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
if file?
@title = nil
else
@title = name
end
@volume = nil
super()
end
|
Instance Attribute Details
Returns the value of attribute chapters.
72
73
74
|
# File 'lib/review/book/part.rb', line 72
def chapters
@chapters
end
|
Returns the value of attribute name.
73
74
75
|
# File 'lib/review/book/part.rb', line 73
def name
@name
end
|
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|
if path =~ /PREDEF/
chaps << Chapter.mkchap(book, name)
else
chaps << 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
88
89
90
|
# File 'lib/review/book/part.rb', line 88
def file?
name.present? and path.end_with?('.re')
end
|
92
93
94
95
96
97
98
|
# File 'lib/review/book/part.rb', line 92
def format_number(heading = true)
if heading
I18n.t('part', @number)
else
@number.to_s
end
end
|
#generate_indexes ⇒ Object
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?
100
101
102
|
# File 'lib/review/book/part.rb', line 100
def on_appendix?
false
end
|
79
80
81
82
83
84
85
86
|
# File 'lib/review/book/part.rb', line 79
def volume
if @number && file?
vol = Volume.count_file(File.join(@book.config['contentdir'], @path))
else
vol = Volume.new(0, 0, 0)
end
vol
end
|