Class: ReVIEW::Book::Part

Inherits:
Object show all
Includes:
Compilable
Defined in:
lib/review/book/part.rb

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, #equation, #equation_index, #footnote, #footnote_index, #headline, #headline_index, #icon_index, #image, #image_bound?, #image_index, #indepimage_index, #lines, #list, #list_index, #next_chapter, #numberless_image_index, #prev_chapter, #size, #table, #table_index, #title

Methods included from TextUtils

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

Constructor Details

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

if Part is dummy, ‘number` is nil.



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

def initialize(book, number, chapters, name = '', io = nil)
  @book = book
  @number = number
  @chapters = chapters
  @name = name
  @path = name
  @content = ''
  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')
  end
  if file?
    @title = nil
  else
    @title = name
  end
  @volume = nil
end

Instance Attribute Details

#chaptersObject (readonly)

Returns the value of attribute chapters.



60
61
62
# File 'lib/review/book/part.rb', line 60

def chapters
  @chapters
end

#nameObject (readonly)

Returns the value of attribute name.



61
62
63
# File 'lib/review/book/part.rb', line 61

def name
  @name
end

#numberObject (readonly)

Returns the value of attribute number.



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

def number
  @number
end

Class Method Details

.mkpart(chaps) ⇒ Object



32
33
34
# File 'lib/review/book/part.rb', line 32

def self.mkpart(chaps)
  chaps.empty? ? nil : Part.new(self, nil, chaps)
end

.mkpart_from_namelist(book, names) ⇒ Object



28
29
30
# File 'lib/review/book/part.rb', line 28

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



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

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



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

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

#file?Boolean

Returns:

  • (Boolean)


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

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

#format_number(heading = true) ⇒ Object



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

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

#on_appendix?Boolean Also known as: on_APPENDIX?

Returns:

  • (Boolean)


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

def on_appendix?
  false
end

#volumeObject



67
68
69
70
71
72
73
74
# File 'lib/review/book/part.rb', line 67

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