Class: PdfExportService

Inherits:
Object
  • Object
show all
Includes:
DataExportHelper
Defined in:
app/models/rails_data/export_services/pdf_export_service.rb

Instance Method Summary collapse

Methods included from DataExportHelper

#convert_parameters, #field_result, #footer_result, #header_result

Instance Method Details

#ending_dataObject



50
51
52
53
54
55
56
# File 'app/models/rails_data/export_services/pdf_export_service.rb', line 50

def ending_data
  if reportable.respond_to? :ending_data
    reportable.try(:ending_data)
  else
    ''
  end
end

#filename(extension = 'pdf') ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/rails_data/export_services/pdf_export_service.rb', line 58

def filename(extension = 'pdf')
  if file_filename.present?
    filename = file_filename
  elsif reportable.respond_to?(:filename)
    filename = reportable.filename
  else
    filename = "#{reportable_name.camelize}-#{reportable_id}"
  end

  unless filename.end_with?(extension)
    filename << '.' << extension
  end

  filename
end

#header_dataObject



39
40
41
42
43
44
45
46
47
48
# File 'app/models/rails_data/export_services/pdf_export_service.rb', line 39

def header_data
  if reportable.respond_to? :header_info
    reportable.header_info
  else
    [
      ['', ''],
      ['', '']
    ]
  end
end

#pdfObject



5
6
7
8
9
10
11
# File 'app/models/rails_data/export_services/pdf_export_service.rb', line 5

def pdf
  if reportable.respond_to?(:pdf_object)
    @pdf ||= reportable.pdf_object(reportable_name)
  else
    @pdf ||= TablePdf.new
  end
end

#pdf_dataObject



19
20
21
22
23
24
25
# File 'app/models/rails_data/export_services/pdf_export_service.rb', line 19

def pdf_data
  if file_id
    file.read
  else
    pdf_string
  end
end

#pdf_resultObject



31
32
33
34
35
36
37
# File 'app/models/rails_data/export_services/pdf_export_service.rb', line 31

def pdf_result
  pdf.table_data = table_lists.includes(:table_items).map { |i| i.csv_array }
  pdf.header_data = header_data
  pdf.ending_data = ending_data
  pdf.run
  pdf
end

#pdf_stringObject



27
28
29
# File 'app/models/rails_data/export_services/pdf_export_service.rb', line 27

def pdf_string
  pdf_result.render
end

#remove_file_saveObject



13
14
15
16
17
# File 'app/models/rails_data/export_services/pdf_export_service.rb', line 13

def remove_file_save
  self.remove_file = true
  self.save
  self.remove_file = nil
end