Class: ConvertApi::FormatDetector

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

Constant Summary collapse

ANY_FORMAT =
'any'

Instance Method Summary collapse

Constructor Details

#initialize(resource, to_format) ⇒ FormatDetector

Returns a new instance of FormatDetector.



5
6
7
8
# File 'lib/convert_api/format_detector.rb', line 5

def initialize(resource, to_format)
  @resource = resource
  @to_format = to_format
end

Instance Method Details

#runObject



10
11
12
13
14
15
# File 'lib/convert_api/format_detector.rb', line 10

def run
  return ANY_FORMAT if archive?
  return @resource.file_ext.downcase if @resource.is_a?(UploadIO)

  format_from_path || raise(FormatError, 'Unable to detect format')
end