Sha256: 4473cf37c9e3b91ec8d40967a9504759295b9447ebb64dadb69b35c162a83506

Contents?: true

Size: 516 Bytes

Versions: 4

Compression:

Stored size: 516 Bytes

Contents

module ConvertApi
  class FormatDetector
    def initialize(resource)
      @resource = resource
    end

    def run
      extension = File.extname(path).downcase
      format = extension[1..-1]

      raise(FormatError, 'Unable to detect format') if format.nil?

      format
    end

    private

    def path
      case @resource
      when String
        URI(@resource).path
      when File
        @resource.path
      when UploadIO
        @resource.filename
      else
        ''
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
convert_api-1.0.4 lib/convert_api/format_detector.rb
convert_api-1.0.3 lib/convert_api/format_detector.rb
convert_api-1.0.2 lib/convert_api/format_detector.rb
convert_api-1.0.1 lib/convert_api/format_detector.rb