Class: ODDB::FiPDF::ChapterWrapper

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
ext/fipdf/src/chapter_wrapper.rb,
ext/fipdf/test/chapter_wrapper_test.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (ChapterWrapper) initialize(chapter)

A new instance of ChapterWrapper



10
11
12
13
14
# File 'ext/fipdf/src/chapter_wrapper.rb', line 10

def initialize(chapter)
  @wrapper_class = SectionWrapper
  @chapter = chapter
  super
end

Instance Attribute Details

- (Object) wrapper_class=(value) (writeonly)

Sets the attribute wrapper_class

Parameters:

  • value

    the value to set the attribute wrapper_class to.



12
13
14
# File 'ext/fipdf/test/chapter_wrapper_test.rb', line 12

def wrapper_class=(value)
  @wrapper_class = value
end

Instance Method Details

- (Object) each_section(&block)



15
16
17
18
19
# File 'ext/fipdf/src/chapter_wrapper.rb', line 15

def each_section(&block)
  @chapter.sections.each { |section|
    block.call(@wrapper_class.new(section))
  }
end

- (Object) first_section



33
34
35
36
37
# File 'ext/fipdf/src/chapter_wrapper.rb', line 33

def first_section
  unless(@chapter.sections.empty?)
    @wrapper_class.new(@chapter.sections.first)
  end
end

- (Boolean) need_new_page?(height, width, formats)

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'ext/fipdf/src/chapter_wrapper.rb', line 20

def need_new_page?(height, width, formats)
  fmt_heading = formats[:chapter]
  #puts "height original #{height}"
  #puts @chapter.heading
  height_heading = fmt_heading.get_height(@chapter.heading, width)
  #puts height_heading
  height = height - height_heading
  #puts "height minus heading height #{height}"
  first = first_section
  (height <= 0) \
    || (!first.nil? \
    && first.need_new_page?(height, width, formats))
end