Class: FileType::Generic

Inherits:
Object show all
Defined in:
lib/file_type.rb

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.

Raises:

  • (ArgumentError)


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

#baseObject (readonly)

Returns the value of attribute base.



27
28
29
# File 'lib/file_type.rb', line 27

def base
  @base
end

#extObject (readonly)

Returns the value of attribute ext.



27
28
29
# File 'lib/file_type.rb', line 27

def ext
  @ext
end

#pathObject (readonly)

Returns the value of attribute path.



27
28
29
# File 'lib/file_type.rb', line 27

def path
  @path
end

Class Method Details

.extractable(aCommand) ⇒ Object



70
71
72
73
# File 'lib/file_type.rb', line 70

def self.extractable ( aCommand )
  include Extractable
  self.extract_command = aCommand
end

.extractable_dir(aCommand) ⇒ Object



75
76
77
78
# File 'lib/file_type.rb', line 75

def self.extractable_dir ( 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

#+(arg) ⇒ Object



66
67
68
# File 'lib/file_type.rb', line 66

def + ( arg )
  @path + arg.to_s
end

#extractable?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/file_type.rb', line 80

def extractable?
  false
end

#extsplitObject



44
45
46
# File 'lib/file_type.rb', line 44

def extsplit
  [@base, @ext]
end

#installable?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/file_type.rb', line 84

def installable?
  false
end

#to_sObject



53
54
55
# File 'lib/file_type.rb', line 53

def to_s
  @path.to_s
end