Sha256: f3fb93bb6470d7473319d93751940c855441aeccfddaa48f25b1cab862c7f4a7

Contents?: true

Size: 699 Bytes

Versions: 1

Compression:

Stored size: 699 Bytes

Contents

require 'mime/types'
require 'safe_shell'

module Wand
  def self.wave(path, options={})
    type = MIME::Types.type_for(options[:original_filename] || path)[0].to_s
    type = parse_type(execute_file_cmd(path)) if blank?(type)
    type = nil if type =~ /^cannot/i
    type
  end

  def self.executable
    @executable ||= `which file`.chomp
  end

  def self.executable=(path)
    @executable = path
  end

private
  def self.parse_type(output)
    type = output.split(';')[0]
    type = type.strip unless type.nil?
    type
  end

  def self.execute_file_cmd(path)
    SafeShell.execute("#{executable}", "--mime", "--brief", path)
  end

  def self.blank?(str)
    str.nil? || str == ''
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wand-0.4 lib/wand.rb