Class: Medivo::PdfGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf/medivo/pdf_group.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePdfGroup

Returns a new instance of PdfGroup.



6
7
8
# File 'lib/pdf/medivo/pdf_group.rb', line 6

def initialize
  @pdfs = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



22
23
24
25
# File 'lib/pdf/medivo/pdf_group.rb', line 22

def method_missing(method, *args, &block)
  @self_before_instance_eval = self.class.instance_variable_get :@self_before_instance_eval
  @self_before_instance_eval.send method, *args, &block
end

Instance Attribute Details

#pdfObject (readonly)

Returns the value of attribute pdf.



4
5
6
# File 'lib/pdf/medivo/pdf_group.rb', line 4

def pdf
  @pdf
end

Class Method Details

.create(&block) ⇒ Object

create a pdf group returns you a PdfGroup class to get the pdf call #pdf, or read the pdf byes, call #read



13
14
15
16
17
18
19
20
# File 'lib/pdf/medivo/pdf_group.rb', line 13

def self.create(&block)
  raise "need to pass a block do create" unless block_given?
  @self_before_instance_eval = eval "self", block.binding
  pdf_group = PdfGroup.new
  pdf_group.instance_eval &block
  pdf_group.combine_pdfs
  pdf_group
end

Instance Method Details

#closeObject

don’t really have to do close the pdf, but I think it will trash quicker if you do



68
69
70
71
72
73
# File 'lib/pdf/medivo/pdf_group.rb', line 68

def close
  if pdf
    pdf.close
    pdf.unlink
  end
end

#combine_pdfsObject

Combines the PDFs



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/pdf/medivo/pdf_group.rb', line 51

def combine_pdfs
  @pdf = PdfGenerator.tmp_pdf(false) do |pdf|
    args = [@pdfs.collect(&:path), 'cat', 'output', pdf.path].join(' ')
    `pdftk #{args}`
  end

  @pdfs.each do |file|
    file.close
    file.unlink if file.respond_to? :unlink
  end
end

#lab_requisition(requisition_id) ⇒ Object



35
36
37
38
# File 'lib/pdf/medivo/pdf_group.rb', line 35

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

#lab_result(requisition_id) ⇒ Object



40
41
42
43
# File 'lib/pdf/medivo/pdf_group.rb', line 40

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

#readObject



63
64
65
# File 'lib/pdf/medivo/pdf_group.rb', line 63

def read
  pdf.read
end

#static_pdf(path) ⇒ Object



45
46
47
# File 'lib/pdf/medivo/pdf_group.rb', line 45

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

#variable_fields(file_path, variables) ⇒ Object



27
28
29
# File 'lib/pdf/medivo/pdf_group.rb', line 27

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

#variable_fields_with_images(file_path, variables, image_data) ⇒ Object



31
32
33
# File 'lib/pdf/medivo/pdf_group.rb', line 31

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