Class: Renalware::Letters::Printing::BatchCompilePdfs

Inherits:
Object
  • Object
show all
Includes:
PdfCombining
Defined in:
app/models/renalware/letters/printing/batch_compile_pdfs.rb

Overview

Given a Batch object that has many associated letters, it

  • compiles each letter with a cover sheet for each recipient, adding blank padding pages if needed to ensure the envelop stuffer will work correctly (ie each letter starts on an odd page)

  • combines all these letter PDFs into one batch PDF. The output filepath is stored on the

batch model.

Note that this class creates files and combines them using ghost script. These operations take place in the current working directory, so to use this class you might need to create a OS tmp folder first and cdhir into it. See the spec for an example.

Constant Summary collapse

PAGE_COUNTS =
%w(2 3 4 5 6 7 8 9 10).freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PdfCombining

#combine_multiple_pdfs_into_file, #combine_multiple_pdfs_using_filenames, #move_tempfile_to_output_file, #rails_tmp_folder, #shell_to_ghostscript_to_combine_files, #using_a_temporary_output_file

Constructor Details

#initialize(batch, user) ⇒ BatchCompilePdfs

Returns a new instance of BatchCompilePdfs.



27
28
29
30
31
32
# File 'app/models/renalware/letters/printing/batch_compile_pdfs.rb', line 27

def initialize(batch, user)
  @batch = batch
  @user = user
  @dir = Pathname(Dir.pwd)
  Rails.logger.info "Compiling letter PDFs for batch #{batch.id} in folder #{dir}"
end

Class Method Details

.call(batch, user) ⇒ Object



23
24
25
# File 'app/models/renalware/letters/printing/batch_compile_pdfs.rb', line 23

def self.call(batch, user)
  new(batch, user).call
end

Instance Method Details

#callObject

rubocop:disable Metrics/AbcSize



35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/renalware/letters/printing/batch_compile_pdfs.rb', line 35

def call
  batch.status = :processing
  batch.save_by!(user)
  batch.items.each do |item|
    validate_letter(item.letter)
    assemble_letter_pdfs(item.letter, dir)
    item.update(status: :compiled)
  end
  batch.filepath = append_files
  batch.status = :awaiting_printing
  batch.save_by!(user)
end