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

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

Overview

  • takes a batch of letters

  • compiles each letter along with its recipient cover sheets

  • adds blank pages to make sure the letter always starts on an odd page

  • appends all PDF letters

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.



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

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



16
17
18
# File 'app/models/renalware/letters/printing/batch_compile_pdfs.rb', line 16

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

Instance Method Details

#callObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/renalware/letters/printing/batch_compile_pdfs.rb', line 27

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