Class: ODDB::FiPDF::SectionWrapper

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(section) ⇒ SectionWrapper

Returns a new instance of SectionWrapper.



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

def initialize(section)
	@wrapper_class = ParagraphWrapper
	@section = section
	super
end

Instance Attribute Details

#wrapper_class=(value) ⇒ Object (writeonly)

Sets the attribute wrapper_class

Parameters:

  • value

    the value to set the attribute wrapper_class to.



14
15
16
# File 'ext/fipdf/test/section_wrapper_test.rb', line 14

def wrapper_class=(value)
  @wrapper_class = value
end

Instance Method Details

#each_paragraph(&block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'ext/fipdf/src/section_wrapper.rb', line 15

def each_paragraph(&block)
	#special call for first paragraph adding the subheading
	first = first_paragraph
	unless(first.nil?)
		block.call(first)
		paragraphs = @section.paragraphs.dup
		paragraphs.shift
		paragraphs.each { |paragraph|
			block.call(@wrapper_class.new(paragraph))
		}
	end
end

#first_paragraphObject



42
43
44
45
46
47
48
49
50
# File 'ext/fipdf/src/section_wrapper.rb', line 42

def first_paragraph
	return if(@section.paragraphs.empty?)
	first_paragraph = @section.paragraphs.first
	if(fix_subheading? && !@section.subheading.empty?)
		first_paragraph = Marshal.load(Marshal.dump(first_paragraph))
		first_paragraph.prepend(@section.subheading + " ", :italic)
	end
	@wrapper_class.new(first_paragraph)
end

#fix_subheading?Boolean

Returns:

  • (Boolean)


51
52
53
54
# File 'ext/fipdf/src/section_wrapper.rb', line 51

def fix_subheading?
	@section.paragraphs.first.respond_to?(:prepend) \
		&& @section.subheading[-1] != ?\n
end

#need_new_page?(height, width, formats) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
37
38
# File 'ext/fipdf/src/section_wrapper.rb', line 27

def need_new_page?(height, width, formats)
	fmt_subheading = formats[:section]
	#puts "height original #{height}"
	height_subheading = fmt_subheading.get_height(self.subheading, width)
	#puts "height subheading #{height_subheading}"
	height -= height_subheading 
	#puts "height - subheading  #{height}"
	
	(height <= 0) \
       || ((first = first_paragraph) \
		    && first.need_new_page?(height, width, formats))
end

#subheadingObject



39
40
41
# File 'ext/fipdf/src/section_wrapper.rb', line 39

def subheading
	(fix_subheading?) ? '' : "<i>" +  @section.subheading.strip + "</i>"
end