Module: Gonzui::Extractor

Extended by:
Util
Defined in:
lib/gonzui/extractor.rb

Constant Summary collapse

ExtractorRegistry =
{}

Class Method Summary collapse

Methods included from Util

assert, assert_equal, assert_equal_all, assert_non_nil, assert_not_reached, benchmark, command_exist?, commify, eprintf, format_bytes, program_name, protect_from_signals, require_command, set_verbosity, shell_escape, unix?, vprintf, windows?, wprintf

Class Method Details

.extnamesObject



23
24
25
# File 'lib/gonzui/extractor.rb', line 23

def extnames
  ExtractorRegistry.keys
end

.get_archive_extname(file_name) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/gonzui/extractor.rb', line 27

def get_archive_extname(file_name)
  ExtractorRegistry.keys.each {|extname|
    pattern = Regexp.new(Regexp.quote(extname) + '$') #'
    return extname if pattern.match(file_name)
  }
  return nil
end

.new(config, file_name) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/gonzui/extractor.rb', line 45

def new(config, file_name)
  extname = get_archive_extname(file_name)
  if klass = ExtractorRegistry[extname]
    return klass.new(config, file_name)
  else
    raise ExtractorError.new("#{extname}: unsupported archive")
  end
end

.register(klass) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/gonzui/extractor.rb', line 54

def register(klass)
  klass.commands.each {|command|
    return unless command_exist?(command)
  }
  klass.extnames.each {|extname|
    assert(!ExtractorRegistry.include?(extname))
    ExtractorRegistry[extname] = klass
  }
end

.supported_file?(file_name) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/gonzui/extractor.rb', line 35

def supported_file?(file_name)
  ExtractorRegistry.include?(get_archive_extname(file_name))
end

.suppress_archive_extname(file_name) ⇒ Object



39
40
41
42
43
# File 'lib/gonzui/extractor.rb', line 39

def suppress_archive_extname(file_name)
  extname = get_archive_extname(file_name)
  pattern = Regexp.new(Regexp.quote(extname) + '$') #'
  return file_name.gsub(pattern, "")
end