filedesc 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/filedesc.rb +63 -0
- metadata +55 -0
data/lib/filedesc.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
module FileDescription
|
2
|
+
|
3
|
+
OPTIONS = {:executable => '/usr/bin/file' }
|
4
|
+
|
5
|
+
def mime
|
6
|
+
@mime ||= get_output('-I')
|
7
|
+
@mime
|
8
|
+
end
|
9
|
+
def is_a_mime?(type)
|
10
|
+
return case type
|
11
|
+
when String
|
12
|
+
mime == type
|
13
|
+
when Regexp
|
14
|
+
!(mime !~ type)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def description
|
19
|
+
@description ||= get_output
|
20
|
+
@description
|
21
|
+
end
|
22
|
+
|
23
|
+
def has_description?(regexp)
|
24
|
+
!(description !~ regexp)
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def extension
|
29
|
+
self.path.scan(/\.([A-za-z0-9]+)$/).to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
def inspect
|
33
|
+
"#<File:#{self.path}, mime: '#{mime}', description: '#{description}', extension: '#{extension}' >"
|
34
|
+
end
|
35
|
+
|
36
|
+
def info
|
37
|
+
{
|
38
|
+
:filename => File.basename(self.path),
|
39
|
+
:mime => mime,
|
40
|
+
:description => description,
|
41
|
+
:extension => extension,
|
42
|
+
:directory => File.dirname(self.path),
|
43
|
+
:path => self.path,
|
44
|
+
:size => File.size(self.path),
|
45
|
+
:last_modified => File.mtime(self.path),
|
46
|
+
:last_access => File.atime(self.path),
|
47
|
+
:executable => File.executable?(self.path),
|
48
|
+
:gid => File.stat(self.path).gid,
|
49
|
+
:uid => File.stat(self.path).uid,
|
50
|
+
:mode => File.stat(self.path).mode
|
51
|
+
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def get_output(params="")
|
57
|
+
`#{OPTIONS[:executable]} -b #{params} '#{self.path}'`.strip
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class File
|
62
|
+
include FileDescription
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: filedesc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shairon Toledo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-29 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: shairon.toledo@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/filedesc.rb
|
26
|
+
has_rdoc: true
|
27
|
+
homepage: http://github.com/shairontoledo/filedesc
|
28
|
+
licenses: []
|
29
|
+
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: "0"
|
40
|
+
version:
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
requirements: []
|
48
|
+
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.3.4
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: A wrapper that works with ruby File class to get information about the system(unix-only)
|
54
|
+
test_files: []
|
55
|
+
|