Class: Shrine::Plugins::DetermineMimeType::MimeTypeAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/shrine/plugins/determine_mime_type.rb

Constant Summary collapse

SUPPORTED_TOOLS =
[:fastimage, :file, :filemagic, :mimemagic, :marcel, :mime_types, :mini_mime, :content_type]
MAGIC_NUMBER =
256 * 1024

Instance Method Summary collapse

Constructor Details

#initialize(tool) ⇒ MimeTypeAnalyzer

Returns a new instance of MimeTypeAnalyzer.

Raises:


79
80
81
82
83
# File 'lib/shrine/plugins/determine_mime_type.rb', line 79

def initialize(tool)
  raise Error, "unknown mime type analyzer #{tool.inspect}, supported analyzers are: #{SUPPORTED_TOOLS.join(",")}" unless SUPPORTED_TOOLS.include?(tool)

  @tool = tool
end

Instance Method Details

#call(io, options = {}) ⇒ Object


85
86
87
88
89
90
# File 'lib/shrine/plugins/determine_mime_type.rb', line 85

def call(io, options = {})
  mime_type = send(:"extract_with_#{@tool}", io, options)
  io.rewind

  mime_type
end