Class: EvilPdf
- Inherits:
-
Object
- Object
- EvilPdf
- Defined in:
- lib/evil_pdf.rb
Instance Attribute Summary collapse
-
#file_handle ⇒ Object
readonly
Returns the value of attribute file_handle.
Instance Method Summary collapse
- #file_path ⇒ Object
- #from_urls(urls) ⇒ Object
-
#initialize(name, options = {}) ⇒ EvilPdf
constructor
A new instance of EvilPdf.
- #to_file(name) ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ EvilPdf
Returns a new instance of EvilPdf.
6 7 8 9 10 11 |
# File 'lib/evil_pdf.rb', line 6 def initialize(name, = {}) @record = PdfRecord.create :name => name @options = Dir.mkdir './tmp' unless Dir.exists? './tmp' self.class.handle_asynchronously :from_urls if [:async] end |
Instance Attribute Details
#file_handle ⇒ Object (readonly)
Returns the value of attribute file_handle.
4 5 6 |
# File 'lib/evil_pdf.rb', line 4 def file_handle @file_handle end |
Instance Method Details
#file_path ⇒ Object
35 36 37 |
# File 'lib/evil_pdf.rb', line 35 def file_path @file_path ||= "./tmp/#{@record.name.parameterize}-#{Time.now.to_i}.pdf" end |
#from_urls(urls) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/evil_pdf.rb', line 13 def from_urls(urls) @tmp_files = [] urls.each_with_index do |url, i| retrieve(url) and generate(i) end combine if @options[:async] @record.update_attributes :pdf => file_handle else file_handle end end |
#to_file(name) ⇒ Object
27 28 29 |
# File 'lib/evil_pdf.rb', line 27 def to_file(name) PDFKit.new(@html, @options).to_file name end |