Class: Paperclip::Freezer

Inherits:
DocumentProcessor show all
Defined in:
lib/paperclip/document/processors/freezer.rb

Overview

This processor extract first page as thumbnail

Instance Attribute Summary

Attributes inherited from DocumentProcessor

#instance, #tmp_dir

Instance Method Summary collapse

Methods inherited from DocumentProcessor

#basename, #file_path

Constructor Details

#initialize(file, options = {}, attachment = nil) ⇒ Freezer

Returns a new instance of Freezer.



7
8
9
10
11
12
13
# File 'lib/paperclip/document/processors/freezer.rb', line 7

def initialize(file, options = {}, attachment = nil)
  super
  @format = options[:format]
  unless @format == :pdf
    raise Paperclip::Error, "Valid format (pdf) must be specified"
  end
end

Instance Method Details

#makeObject

Convert the document to pdf



16
17
18
19
20
21
22
23
24
25
# File 'lib/paperclip/document/processors/freezer.rb', line 16

def make
  destination_path = tmp_dir.to_s
  destination_file = File.join(destination_path, basename + ".#{@format}")
  if pdf_format?
    destination_file = file_path.to_s
  else
    Docsplit.extract_pdf(file_path.to_s, :output => destination_path)
  end
  return File.open(destination_file)
end

#pdf_format?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
# File 'lib/paperclip/document/processors/freezer.rb', line 28

def pdf_format?
  file_magic = FileMagic.new
  type = file_magic.file(file_path.to_s)
  file_magic.close
  type =~ /pdf/i
end