Class FileMagic
In: lib/filemagic/version.rb
lib/filemagic.rb
Parent: Object

Methods

clear!   fm   inspect   mime   open   simplified?  

Classes and Modules

Module FileMagic::Ext
Module FileMagic::Version

Constants

VERSION = Version.to_s
FLAGS_BY_SYM = [ :none, # No flags :debug, # Turn on debugging :symlink, # Follow symlinks :compress, # Check inside compressed files :devices, # Look at the contents of devices :mime_type, # Return only the MIME type :continue, # Return all matches :check, # Print warnings to stderr :preserve_atime, # Restore access time on exit :raw, # Don't translate unprint chars :error, # Handle ENOENT etc as real errors :mime_encoding, # Return only the MIME encoding :mime, # MAGIC_MIME_TYPE | MAGIC_MIME_ENCODING :apple, # Return the Apple creator and type :no_check_compress, # Don't check for compressed files :no_check_tar, # Don't check for tar files :no_check_soft, # Don't check magic entries :no_check_apptype, # Don't check application type :no_check_elf, # Don't check for elf details :no_check_text, # Don't check for text files :no_check_cdf, # Don't check for cdf files :no_check_tokens, # Don't check ascii/tokens :no_check_encoding, # Don't check text encodings :no_check_ascii, # MAGIC_NO_CHECK_TEXT :no_check_fortran, # Don't check ascii/fortran :no_check_troff   Map flag names to their values (:name => Integer).
FLAGS_BY_INT = FLAGS_BY_SYM.invert.update(0 => :none)   Map flag values to their names (Integer => :name).
SIMPLE_RE = %r{([.\w\/-]+)}   Extract "simple" MIME type

Attributes

simplified  [W] 

Public Class methods

Clear our instance cache.

[Source]

    # File lib/filemagic.rb, line 58
58:     def clear!
59:       @fm.each_value { |fm| fm.close }
60:       @fm.clear
61:     end

Provide a "magic singleton".

[Source]

    # File lib/filemagic.rb, line 52
52:     def fm(*flags)
53:       @fm.delete(flags.to_s) if @fm[flags].closed?
54:       @fm[flags]
55:     end

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

[Source]

    # File lib/filemagic.rb, line 80
80:     def mime(*flags, &block)
81:       open(:mime, *flags, &block)
82:     end

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.

[Source]

    # File lib/filemagic.rb, line 65
65:     def open(*flags)
66:       fm = new(*flags)
67: 
68:       if block_given?
69:         begin
70:           yield fm
71:         ensure
72:           fm.close
73:         end
74:       else
75:         fm
76:       end
77:     end

Public Instance methods

[Source]

    # File lib/filemagic.rb, line 92
92:   def inspect
93:     super.insert(-2, closed? ? ' (closed)' : '')
94:   end

[Source]

    # File lib/filemagic.rb, line 88
88:   def simplified?
89:     @simplified
90:   end

[Validate]