Created
October 2, 2014 04:58
-
-
Save rebelweb/71024b20d50d45349e97 to your computer and use it in GitHub Desktop.
Object Oriented Prawn Report
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Reports | |
class Report | |
#place share report methods here to share among multiple reports | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.