class ConvertApi::FormatDetector

Public Class Methods

new(resource) click to toggle source
# File lib/convert_api/format_detector.rb, line 3
def initialize(resource)
  @resource = resource
end

Public Instance Methods

run() click to toggle source
# File lib/convert_api/format_detector.rb, line 7
def run
  return @resource.file_ext.downcase if @resource.is_a?(UploadIO)

  format_from_path
end

Private Instance Methods

format_from_path() click to toggle source
# File lib/convert_api/format_detector.rb, line 15
def format_from_path
  extension = File.extname(path).downcase
  format = extension[1..-1]
  format || raise(FormatError, 'Unable to detect format')
end
path() click to toggle source
# File lib/convert_api/format_detector.rb, line 21
def path
  case @resource
  when String
    URI(@resource).path
  when File
    @resource.path
  else
    ''
  end
end