Class: PdfEditor::TableOfContents
- Inherits:
-
Object
- Object
- PdfEditor::TableOfContents
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
#resources ⇒ Object
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
#body ⇒ Object
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
resources.inject(begin_page_count) do |page_location, resource|
text "#{resource.name}........................#{page_location}"
move_down 10
page_location + resource.page_count
end
end
|
#call ⇒ Object
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_pdf ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/pdf_editor/table_of_contents.rb', line 26
def create_pdf
update_pdf do
body
end
to_pdf
end
|
34
35
36
37
38
|
# File 'lib/pdf_editor/table_of_contents.rb', line 34
def
move_down 20
text 'applicant_name', size: 40, align: :center
move_down 50
end
|
#post_init ⇒ Object
12
13
14
|
# File 'lib/pdf_editor/table_of_contents.rb', line 12
def post_init
@resources = args.fetch(:resources, [])
end
|