class PdfEditor::Bundle

Attributes

ready_for_toc[RW]
resources[R]
table_of_contents[RW]
title[R]
with_title_pages[R]
with_toc[R]

Public Instance Methods

call() click to toggle source
# File lib/pdf_editor/bundle.rb, line 23
def call
  create_title_pages
  create_table_of_contents
  bundle_documents
end
post_init() click to toggle source
# File lib/pdf_editor/bundle.rb, line 13
def post_init
  @resources         = args.fetch(:resources, [])
  @ready_for_toc     = []
  @table_of_contents = nil

  @title             = args.fetch(:title, '')
  @with_toc          = args.fetch(:with_toc, true)
  @with_title_pages  = args.fetch(:with_title_pages, true)
end

Private Instance Methods

bundle_documents() click to toggle source
# File lib/pdf_editor/bundle.rb, line 33
def bundle_documents
  bundle_resources = ready_for_toc
  bundle_resources.unshift(table_of_contents) if table_of_contents 
  PdfEditor::Merge.call({resources: bundle_resources})
end
create_table_of_contents() click to toggle source
# File lib/pdf_editor/bundle.rb, line 39
def create_table_of_contents
  return if ready_for_toc.empty?
  return unless with_toc

  self.table_of_contents = PdfEditor::TableOfContents.call({resources: ready_for_toc})
end
create_title_page(resource) click to toggle source
# File lib/pdf_editor/bundle.rb, line 72
def create_title_page(resource)
  PdfEditor::TitlePage.call({title: resource.name})
end
create_title_pages() click to toggle source
# File lib/pdf_editor/bundle.rb, line 46
def create_title_pages
  ready_for_toc.clear

  if with_title_pages

    resources.each do |resource|
      new_resource = merge_resource_with_title_page(resource)
      ready_for_toc << new_resource
    end

  else
    self.ready_for_toc = resources.dup
  end

  ready_for_toc
end
merge_resource_with_title_page(resource) click to toggle source
# File lib/pdf_editor/bundle.rb, line 64
def merge_resource_with_title_page(resource)
  title_page_resource = create_title_page(resource)
  PdfEditor::Merge.call({
    resources: [title_page_resource, resource], 
    merged_name: title_page_resource.name
  })
end