Class: File

Inherits:
Object
  • Object
show all
Defined in:
lib/magic/core/file.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.magic(path, flags = Magic::NONE) ⇒ Object

call-seq:

File.magic( path ) -> string, array or nil

Returns

Example:

See also: File::mime and File::type



40
41
42
43
44
45
46
47
# File 'lib/magic/core/file.rb', line 40

def magic(path, flags = Magic::NONE)
  path   = path.path    if path.respond_to?(:path)
  path ||= path.to_path if path.respond_to?(:to_path)
  path ||= path.to_s

  Magic.open(flags) {|mgc| mgc.file(path) }
rescue Magic::Error
end

.mime(path) ⇒ Object

call-seq:

File.mime( path ) -> string, array or nil

Returns

Example:

See also: File::magic and File::type



59
60
61
# File 'lib/magic/core/file.rb', line 59

def mime(path)
  magic(path, Magic::MIME)
end

.type(path) ⇒ Object

call-seq:

File.type( path ) -> string, array or nil

Returns

Example:

See also: File::magic and File::mime



73
74
75
# File 'lib/magic/core/file.rb', line 73

def type(path)
  magic(path, Magic::MIME_TYPE)
end

Instance Method Details

#magicObject

call-seq:

File.magic( path ) -> string, array or nil

Returns

Example:

See also: File#mime and File#type



88
89
90
# File 'lib/magic/core/file.rb', line 88

def magic
  self.class.magic(self)
end

#mimeObject

call-seq:

File.mime( path ) -> string, array or nil

Returns

Example:

See also: File#magic and File#type



102
103
104
# File 'lib/magic/core/file.rb', line 102

def mime
  self.class.mime(self)
end

#typeObject

call-seq:

File.type( path ) -> string, array or nil

Returns

Example:

See also: File#magic and File#mime



116
117
118
# File 'lib/magic/core/file.rb', line 116

def type
  self.class.type(self)
end