Class: EvilPdf

Inherits:
Object
  • Object
show all
Defined in:
lib/evil_pdf.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @record = PdfRecord.create :name => name
  @options = options
  Dir.mkdir './tmp' unless Dir.exists? './tmp'
  self.class.handle_asynchronously :from_urls if options[:async]
end

Instance Attribute Details

#file_handleObject (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_pathObject



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