Class: Receipt::Pdf
- Inherits:
-
Object
- Object
- Receipt::Pdf
- Extended by:
- Forwardable
- Includes:
- Prawn::View
- Defined in:
- lib/receipt/pdf.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #after_receipt_box(&block) ⇒ Object
- #before_receipt_box(&block) ⇒ Object
- #currency ⇒ Object
- #data ⇒ Object
- #file ⇒ Object
- #filename ⇒ Object
-
#initialize(params) ⇒ Pdf
constructor
A new instance of Pdf.
- #mimetype ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(params) ⇒ Pdf
Returns a new instance of Pdf.
28 29 30 31 32 33 |
# File 'lib/receipt/pdf.rb', line 28 def initialize(params) @params = OpenStruct.new(params) setup_i18n @errors = {} end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
11 12 13 |
# File 'lib/receipt/pdf.rb', line 11 def errors @errors end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
11 12 13 |
# File 'lib/receipt/pdf.rb', line 11 def params @params end |
Instance Method Details
#after_receipt_box(&block) ⇒ Object
56 57 58 |
# File 'lib/receipt/pdf.rb', line 56 def after_receipt_box(&block) @after ||= block end |
#before_receipt_box(&block) ⇒ Object
52 53 54 |
# File 'lib/receipt/pdf.rb', line 52 def before_receipt_box(&block) @before ||= block end |
#currency ⇒ Object
84 85 86 |
# File 'lib/receipt/pdf.rb', line 84 def currency params.currency || t('receipt.currency') end |
#data ⇒ Object
35 36 37 38 39 40 |
# File 'lib/receipt/pdf.rb', line 35 def data return unless valid? generate render end |
#file ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/receipt/pdf.rb', line 42 def file return unless valid? @file ||= lambda do generate save_as(path) path end.call end |
#filename ⇒ Object
76 77 78 |
# File 'lib/receipt/pdf.rb', line 76 def filename File.basename(path) end |
#mimetype ⇒ Object
80 81 82 |
# File 'lib/receipt/pdf.rb', line 80 def mimetype 'application/pdf' end |
#valid? ⇒ Boolean
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/receipt/pdf.rb', line 60 def valid? [ :id, :amount, :payer, :receiver, :description ].each do |p| if params.send(p).to_s.empty? @errors[p] = t('receipt.errors.required_param_not_found') end end @errors.size == 0 end |