Advertisement
saasbook

ocp_decorator.rb

Aug 15th, 2013
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.72 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 ; ... ; end
  8.   def output
  9.     @base.output.protect_with_password
  10.   end
  11. end  
  12. class PdfWithWatermarkFormatter < PdfFormatter
  13.   def initialize(base) ; @base = base ; end
  14.   def add_watermark ; ... ; end
  15.   def output
  16.     @base.output.add_watermark
  17.   end
  18. end
  19. # If we just want a plain PDF
  20. formatter = PdfFormatter.new
  21. # If we want a "draft" watermark
  22. formatter = PdfWithWatermarkFormatter.new(PdfFormatter.new)
  23. # Both password protection and watermark
  24. formatter = PdfWithWatermarkFormatter.new(
  25.   PdfWithPasswordFormatter.new(PdfFormatter.new))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement