Class: MediaInformationGatherer::MediaType

Inherits:
Object
  • Object
show all
Defined in:
lib/mig/modules/media_type.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MediaType

Returns a new instance of MediaType.



6
# File 'lib/mig/modules/media_type.rb', line 6

def initialize(options = {}); end

Instance Method Details

#run(file_path, options = { }) ⇒ Hash

Returns Will contain :type, :subtype and any other attributes output during the call.

Returns:

  • (Hash)

    Will contain :type, :subtype and any other attributes output during the call



11
12
13
14
15
16
17
18
19
20
# File 'lib/mig/modules/media_type.rb', line 11

def run(file_path, options = { })
    media_type, charset = (File.mime_type(file_path) || '').split(';')
    type, subtype = media_type.split('/') if media_type.is_a?(String)
    output = { :type => type, :subtype => subtype }

    param = charset.strip.split('=') if charset.is_a?(String)
    output[param.first] = param.last if param.is_a?(Array)

    output
end