Class: Paperclip::ContentTypeDetector

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

Constant Summary collapse

EMPTY_TYPE =
"inode/x-empty"
SENSIBLE_DEFAULT =
"application/octet-stream"

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ ContentTypeDetector

Returns a new instance of ContentTypeDetector.



6
7
8
# File 'lib/paperclip/content_type_detector.rb', line 6

def initialize(filename)
  @filename = filename
end

Instance Method Details

#detectObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/paperclip/content_type_detector.rb', line 10

def detect
  if blank?
    SENSIBLE_DEFAULT
  elsif empty?
    EMPTY_TYPE
  elsif !match?
    type_from_file_command
  elsif !multiple?
    possible_types.first
  else
    best_type_match
  end.to_s
end