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 or array

Returns

Example:

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



40
41
42
43
44
45
46
# 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 | Magic::ERROR) {|mgc| mgc.file(path) }
end

.mime(path) ⇒ Object

call-seq:

File.mime( path ) -> string or array

Returns

Example:

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



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

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

.type(path) ⇒ Object

call-seq:

File.type( path ) -> string or array

Returns

Example:

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



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

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

Instance Method Details

#magicObject

call-seq:

File.magic( path ) -> string or array

Returns

Example:

See also: File#mime and File#type



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

def magic
  self.class.magic(self)
end

#mimeObject

call-seq:

File.mime( path ) -> string or array

Returns

Example:

See also: File#magic and File#type



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

def mime
  self.class.mime(self)
end

#typeObject

call-seq:

File.type( path ) -> string or array

Returns

Example:

See also: File#magic and File#mime



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

def type
  self.class.type(self)
end