Class: Beardley::Report
- Inherits:
-
Object
- Object
- Beardley::Report
- Defined in:
- lib/beardley/report.rb
Overview
This class permit to produce reports in PDF, ODT and DOCX using Jasper
Instance Attribute Summary collapse
-
#object_file ⇒ Object
readonly
Returns the value of attribute object_file.
-
#source_file ⇒ Object
readonly
Returns the value of attribute source_file.
Instance Method Summary collapse
-
#initialize(report, options = {}) ⇒ Report
constructor
Constructor for a report generator.
-
#to_csv(*args) ⇒ Object
Export report to CSV with given datasource.
-
#to_docx(*args) ⇒ Object
Export report to DOCX with given datasource.
-
#to_ods(*args) ⇒ Object
Export report to ODS with given datasource.
-
#to_odt(*args) ⇒ Object
Export report to ODT with given datasource.
-
#to_pdf(*args) ⇒ Object
Export report to PDF with given datasource.
-
#to_xlsx(*args) ⇒ Object
Export report to XLSX with given datasource.
Constructor Details
#initialize(report, options = {}) ⇒ Report
Constructor for a report generator
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/beardley/report.rb', line 31 def initialize(report, = {}) @parameters = .delete(:report) || {} @source_file, @object_file = nil, nil if report.is_a?(Pathname) @source_file = report if report.extname.downcase == ".jrxml" or report.extname.downcase == ".xml" @object_file = report if report.extname.downcase == ".jasper" elsif report.is_a?(String) hash = Digest::SHA256.hexdigest(report) @source_file = Pathname.new([:tmp_dir] || "/tmp").join("report-" + hash + '.jrxml') File.open(@source_file, 'wb') do |f| f.write(report) end end @object_file ||= @source_file.dirname.join(@source_file.basename.to_s + ".jasper") raise ArgumentError.new("An object must be given at least") unless @object_file.is_a?(Pathname) end |
Instance Attribute Details
#object_file ⇒ Object (readonly)
Returns the value of attribute object_file.
28 29 30 |
# File 'lib/beardley/report.rb', line 28 def object_file @object_file end |
#source_file ⇒ Object (readonly)
Returns the value of attribute source_file.
28 29 30 |
# File 'lib/beardley/report.rb', line 28 def source_file @source_file end |
Instance Method Details
#to_csv(*args) ⇒ Object
Export report to CSV with given datasource
66 67 68 |
# File 'lib/beardley/report.rb', line 66 def to_csv(*args) return to(:csv, *args) end |
#to_docx(*args) ⇒ Object
Export report to DOCX with given datasource
71 72 73 |
# File 'lib/beardley/report.rb', line 71 def to_docx(*args) return to(:docx, *args) end |
#to_ods(*args) ⇒ Object
Export report to ODS with given datasource
61 62 63 |
# File 'lib/beardley/report.rb', line 61 def to_ods(*args) return to(:ods, *args) end |
#to_odt(*args) ⇒ Object
Export report to ODT with given datasource
56 57 58 |
# File 'lib/beardley/report.rb', line 56 def to_odt(*args) return to(:odt, *args) end |
#to_pdf(*args) ⇒ Object
Export report to PDF with given datasource
49 50 51 52 53 |
# File 'lib/beardley/report.rb', line 49 def to_pdf(*args) = (args) datasource = args[0] return JasperExportManager._invoke('exportReportToPdf', 'Lnet.sf.jasperreports.engine.JasperPrint;', prepare(datasource)) end |
#to_xlsx(*args) ⇒ Object
Export report to XLSX with given datasource
76 77 78 |
# File 'lib/beardley/report.rb', line 76 def to_xlsx(*args) return to(:xlsx, *args) end |