Parent

Namespace

FileMagic

Constants

FLAGS_BY_INT

Map flag values to their names (Integer => :name).

FLAGS_BY_SYM

Map flag names to their values (:name => Integer).

SIMPLE_RE

Extract “simple” MIME type

VERSION

Attributes

simplified[W]

Public Class Methods

clear!() click to toggle source

Clear our instance cache.

# File lib/filemagic.rb, line 58
def clear!
  @fm.each_value { |fm| fm.close }
  @fm.clear
end
fm(*flags) click to toggle source

Provide a “magic singleton”.

# File lib/filemagic.rb, line 52
def fm(*flags)
  @fm.delete(flags.to_s) if @fm[flags].closed?
  @fm[flags]
end
mime(*flags, &block) click to toggle source

Just a short-cut to open with the mime flag set.

# File lib/filemagic.rb, line 80
def mime(*flags, &block)
  open(:mime, *flags, &block)
end
open(*flags) click to toggle source

Just like new, but takes an optional block, in which case close is called at the end and the value of the block is returned.

# File lib/filemagic.rb, line 65
def open(*flags)
  fm = new(*flags)

  if block_given?
    begin
      yield fm
    ensure
      fm.close
    end
  else
    fm
  end
end

Public Instance Methods

inspect() click to toggle source
# File lib/filemagic.rb, line 92
def inspect
  super.insert(-2, closed? ? ' (closed)' : '')
end
simplified?() click to toggle source
# File lib/filemagic.rb, line 88
def simplified?
  @simplified
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.