Class: Shrine::Plugins::InferExtension::ExtensionInferrer

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

Constant Summary collapse

SUPPORTED_TOOLS =
[:mime_types, :mini_mime]

Instance Method Summary collapse

Constructor Details

#initialize(tool) ⇒ ExtensionInferrer

Returns a new instance of ExtensionInferrer.

Raises:


75
76
77
78
79
# File 'lib/shrine/plugins/infer_extension.rb', line 75

def initialize(tool)
  raise Error, "unknown extension inferrer #{tool.inspect}, supported inferrers are: #{SUPPORTED_TOOLS.join(",")}" unless SUPPORTED_TOOLS.include?(tool)

  @tool = tool
end

Instance Method Details

#call(mime_type) ⇒ Object


81
82
83
84
85
86
87
# File 'lib/shrine/plugins/infer_extension.rb', line 81

def call(mime_type)
  return nil if mime_type.nil?

  extension = send(:"infer_with_#{@tool}", mime_type)
  extension = ".#{extension}" unless extension.nil? || extension.start_with?(".")
  extension
end