Class: FileType::Generic
Direct Known Subclasses
Bz2, Directory, Gem, Gz, Ruby, Tar, TarBz2, TarGz, Unknown, Yaml, Zip
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(path) ⇒ Generic
Returns a new instance of Generic.
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/file_type.rb', line 29
def initialize ( path )
@path = Pathname.new(path)
re = self.class.extension
raise ArgumentError, "bad class #{self.class}" if re.nil?
unless @path.to_s =~ re
raise ArgumentError, "#{@path} do not match /#{re.source}/"
end
@base, @ext = $`, $&
if @ext.empty?
@base = self
else
@base = FileType.guess(@base)
end
end
|
Instance Attribute Details
Returns the value of attribute base.
27
28
29
|
# File 'lib/file_type.rb', line 27
def base
@base
end
|
Returns the value of attribute ext.
27
28
29
|
# File 'lib/file_type.rb', line 27
def ext
@ext
end
|
Returns the value of attribute path.
27
28
29
|
# File 'lib/file_type.rb', line 27
def path
@path
end
|
Class Method Details
70
71
72
73
|
# File 'lib/file_type.rb', line 70
def self. ( aCommand )
include Extractable
self.extract_command = aCommand
end
|
75
76
77
78
|
# File 'lib/file_type.rb', line 75
def self. ( aCommand )
include ExtractableDir
self.extract_command = aCommand
end
|
.filetype_extension(anObject, priority = 1) ⇒ Object
88
89
90
91
92
93
94
|
# File 'lib/file_type.rb', line 88
def self.filetype_extension ( anObject, priority=1 )
class_eval do
self.extension = anObject
self.priority = priority
concrete
end
end
|
.inherited(klass) ⇒ Object
48
49
50
51
|
# File 'lib/file_type.rb', line 48
def self.inherited ( klass )
FileType.register(klass)
super
end
|
.match_type(path, max, best) ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'lib/file_type.rb', line 57
def self.match_type ( path, max, best )
ext_re = self.extension
if path.to_s =~ ext_re
cur = $&.size * self.priority
return [cur, self] if cur > max
end
return [max, best]
end
|
Instance Method Details
66
67
68
|
# File 'lib/file_type.rb', line 66
def + ( arg )
@path + arg.to_s
end
|
80
81
82
|
# File 'lib/file_type.rb', line 80
def
false
end
|
44
45
46
|
# File 'lib/file_type.rb', line 44
def extsplit
[@base, @ext]
end
|
#installable? ⇒ Boolean
84
85
86
|
# File 'lib/file_type.rb', line 84
def installable?
false
end
|
53
54
55
|
# File 'lib/file_type.rb', line 53
def to_s
@path.to_s
end
|