Module: Axlsx::MimeTypeUtils

Defined in:
lib/axlsx/util/mime_type_utils.rb

Overview

This module defines some utils related with mime type detection

Class Method Summary collapse

Class Method Details

.get_mime_type(v) ⇒ String

Detect a file mime type

Parameters:

  • v (String)

    File path

Returns:

  • (String)

    File mime type



9
10
11
# File 'lib/axlsx/util/mime_type_utils.rb', line 9

def self.get_mime_type(v)
  Marcel::MimeType.for(Pathname.new(v))
end

.get_mime_type_from_uri(v) ⇒ String

Detect a file mime type from URI

Parameters:

  • v (String)

    URI

Returns:

  • (String)

    File mime type



16
17
18
19
20
21
22
# File 'lib/axlsx/util/mime_type_utils.rb', line 16

def self.get_mime_type_from_uri(v)
  if URI.respond_to?(:open)
    Marcel::MimeType.for(URI.open(v))
  else
    Marcel::MimeType.for(URI.parse(v).open)
  end
end