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

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, #next_chapter, #numberless_image_index, #open, #prev_chapter, #size, #table, #table_index, #title

Methods included from TextUtils

#detab, #split_paragraph

Constructor Details

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

if Part is dummy, ‘number` is nil.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/review/book/part.rb', line 20

def initialize(book, number, chapters, name = "", io = nil)
  @book = book
  @number = number
  @chapters = chapters
  @path = name
  @title = nil
  if io
    @content = io.read
  elsif @path && File.exist?(@path)
    @content = File.read(@path, :mode => 'r:BOM|utf-8')
  else
    @content = nil
  end
  @name = name ? File.basename(name, '.re') : nil
  @volume = nil
end

Instance Attribute Details

#chaptersObject (readonly)

Returns the value of attribute chapters.



38
39
40
# File 'lib/review/book/part.rb', line 38

def chapters
  @chapters
end

#nameObject (readonly)

Returns the value of attribute name.



39
40
41
# File 'lib/review/book/part.rb', line 39

def name
  @name
end

#numberObject (readonly)

Returns the value of attribute number.



37
38
39
# File 'lib/review/book/part.rb', line 37

def number
  @number
end

Instance Method Details

#each_chapter(&block) ⇒ Object



41
42
43
# File 'lib/review/book/part.rb', line 41

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

#file?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/review/book/part.rb', line 51

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

#format_number(heading = true) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/review/book/part.rb', line 55

def format_number(heading = true)
  if heading
    "#{I18n.t("part", @number)}"
  else
    "#{@number}"
  end
end

#on_APPENDIX?Boolean

Returns:

  • (Boolean)


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

def on_APPENDIX?
  false
end

#volumeObject



45
46
47
48
49
# File 'lib/review/book/part.rb', line 45

def volume
  vol = Volume.sum(@chapters.map {|chap| chap.volume })
  vol.page_per_kbyte = @book.page_metric.page_per_kbyte
  vol
end