Sha256: bc5ce368f73c8ee8610289460e3bf659701f3f6a945a000725941f8e25cb7812

Contents?: true

Size: 1009 Bytes

Versions: 1

Compression:

Stored size: 1009 Bytes

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 variable_fields(file_path, variables)
      @pdfs << PdfGenerator.variable_fields(file_path, variables)
    end

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

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

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

    ##
    # Combines the PDFs
    def pdf
      PdfGenerator.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.8 lib/pdf/medivo/pdf_group.rb