Advertisement
saasbook

ocp_decorator.rb

Mar 1st, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.75 KB | None | 0 0
  1. class PdfFormatter
  2.   def initialize ; ... ; end
  3.   def output ; ... ; end
  4. end
  5. class PdfWithPasswordFormatter < PdfFormatter
  6.   def initialize(base) ; @base = base ; end
  7.   def protect_with_password(original_output) ; ... ; end
  8.   def output ; protect_with_password @base.output ; end
  9. end  
  10. class PdfWithWatermarkFormatter < PdfFormatter
  11.   def initialize(base) ; @base = base ; end
  12.   def add_watermark(original_output) ; ... ; end
  13.   def output ; add_watermark @base.output ; end
  14.   end
  15. end
  16. # If we just want a plain PDF
  17. formatter = PdfFormatter.new
  18. # If we want a "draft" watermark
  19. formatter = PdfWithWatermarkFormatter.new(PdfFormatter.new)
  20. # Both password protection and watermark
  21. formatter = PdfWithWatermarkFormatter.new(
  22.   PdfWithPasswordFormatter.new(PdfFormatter.new))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement