Class: PdfEditor::TableOfContents

Inherits:
Object
  • Object
show all
Includes:
PrawnDSL, Service
Defined in:
lib/pdf_editor/table_of_contents.rb

Constant Summary

Constants included from Service

Service::InterfaceNotImplementedError, Service::MustPassBlockToAsTempfile

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PrawnDSL

#document, #method_missing, #respond_to_missing?, #save_to_file, #to_pdf, #update_pdf

Methods included from Service

included, #initialize

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PdfEditor::PrawnDSL

Instance Attribute Details

#resourcesObject (readonly)

Returns the value of attribute resources.



10
11
12
# File 'lib/pdf_editor/table_of_contents.rb', line 10

def resources
  @resources
end

Instance Method Details

#bodyObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/pdf_editor/table_of_contents.rb', line 40

def body
  begin_page_count = 1 # TOC normally doesn't count itself as a page

  resources.inject(begin_page_count) do |page_location, resource|
    text "#{resource.name}........................#{page_location}"
    move_down 10 

    page_location + resource.page_count 
  end
end

#callObject



16
17
18
19
20
21
22
23
24
# File 'lib/pdf_editor/table_of_contents.rb', line 16

def call
  if resources.empty?
    raise PdfEditor::Errors::ResourcesEmptyError, 
          'You must have at least one resource to create a table of contents'
  end
  PdfEditor::Resource.new(
    create_tempfile {create_pdf}
  )
end

#create_pdfObject



26
27
28
29
30
31
32
# File 'lib/pdf_editor/table_of_contents.rb', line 26

def create_pdf
  update_pdf do 
    header
    body
  end
  to_pdf
end

#headerObject



34
35
36
37
38
# File 'lib/pdf_editor/table_of_contents.rb', line 34

def header
  move_down 20
  text 'applicant_name', size: 40, align: :center
  move_down 50
end

#post_initObject



12
13
14
# File 'lib/pdf_editor/table_of_contents.rb', line 12

def post_init
  @resources = args.fetch(:resources, [])
end