Skip to content

Instantly share code, notes, and snippets.

@rebelweb
Created October 2, 2014 04:58
Show Gist options
  • Save rebelweb/71024b20d50d45349e97 to your computer and use it in GitHub Desktop.
Save rebelweb/71024b20d50d45349e97 to your computer and use it in GitHub Desktop.
Object Oriented Prawn Report
require 'prawn'
module Reports
class PrawnReport < Reports::Report
#call this from irb or any ruby code for that matter (i.e. Reports::PrawnReport.generate)
def self.generate
Prawn::Document.generate('prawn.pdf') do |pdf|
report_header(pdf)
report_body(pdf)
end
end
private
#place all pices of the report here
def self.report_header(pdf)
pdf.text 'Prawn Report'
end
def self.report_body(pdf)
pdf.text 'Report Body'
end
end
end
module Reports
class Report
#place share report methods here to share among multiple reports
end
end
@rebelweb
Copy link
Author

rebelweb commented Oct 2, 2014

This is a ruby prawn report built in an object oriented style. This is a basic report, but this style can be used with Rails or a straight database connector such as pg or mysql. The report can also inherit from a master class to share parts and pieces among reports as shown here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment