Sha256: a4151c6da7754c22fb2203a3cac70af508d46f3ea54b0f2a703d0a655b24c62a

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

module Medivo
  class PdfGroup

    def initialize
      @pdfs = []
    end

    def self.create(&block)
      raise "need to pass a block do create" unless block_given?
      pdf_group = PdfGroup.new
      pdf_group.instance_eval &block
      pdf_group.pdf
    end

    def tmp_pdf
      pdf = Tempfile.new('pdf', :encoding => 'ascii-8bit')
      yield pdf
      pdf.close
      pdf
    end

    def variable_fields(file_path, variables)
      @pdfs << PdfGenerator.variable_fields(file_path, variables)
    end

    def lab_requisition(requisition_id)
      @pdfs << tmp_pdf {|pdf| pdf.write Medivo::Order.pdf_requisition(requisition_id) }
    end

    def lab_result(requisition_id)
      @pdfs << tmp_pdf {|pdf| pdf.write Medivo::Order.pdf_result(requisition_id) }
    end

    def static_pdf(path)
      @pdfs << File.new(path)
    end

    ##
    # Combines the PDFs
    def pdf
      tmp_pdf do |pdf|
        args = [@pdfs.collect(&:path), 'cat', 'output', pdf.path].flatten
        system 'pdftk', *args
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
medivo-0.1.7 lib/pdf/medivo/pdf_group.rb