Report abuse


			
module MimeHelper
  def self.is_image?(filename)
    check_content_type filename, ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png']
  end

  def self.is_mp3?(filename)
    check_content_type filename, ['audio/mpeg']
  end

  def self.is_word?(filename)
    check_content_type filename, ['application/msword', 'text/plain', 'application/word']
  end

  def self.is_pdf?(filename)
    check_content_type filename, ['application/pdf']
  end

  def self.is_ppt?(filename)
    check_content_type filename, ['application/vnd.ms-powerpoint', 'application/powerpoint']
  end

  protected
  def self.check_content_type(filename, allowed_content_types)
    MIME::Types.type_for(filename).map(&:content_type).each { |content_type| return true if allowed_content_types.include?(content_type) }
    false
  end
end