Module: TotalCompressor

Defined in:
lib/total_compressor.rb,
lib/total_compressor/version.rb

Defined Under Namespace

Classes: BaseCompressor, T7z, TGzip, TRar, TZip

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.cmdlineObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/total_compressor.rb', line 13

def cmdline
  case ARGV.size
    when 1
      decompress(ARGV[0])
    when 2
      compress(ARGV[1], BaseCompressor::HASH_TYPE[ARGV[0]]) if BaseCompressor::HASH_TYPE[ARGV[0]]
    else
      raise
  end
rescue
  show_help
end

.compress(path, format) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/total_compressor.rb', line 26

def compress(path, format)
  if BaseCompressor::TYPE[format]
    eval("TotalCompressor::T#{format.capitalize}.new.compress(\'#{path}\')")
  else
    ap BaseCompressor::MSG[:unsupported]
  end
end

.decompress(path) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/total_compressor.rb', line 34

def decompress(path)
  format = path.split('.')[-1]
  if BaseCompressor::TYPE[format]
    eval("TotalCompressor::T#{format.capitalize}.new.decompress(\'#{path}\')")
  else
    ap BaseCompressor::MSG[:unsupported]
  end
end

.show_helpObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/total_compressor.rb', line 53

def show_help
  puts %Q{
  Total Compressor, v0.1, 2013, MIT License, https://github.com/phlowerteam
  Tool (wrapper) for compression and handling multiple type of archives.

  Usage: tcomp [<key>] path
    <key> - determine supported type of compression:
      z - use Zip
      g - use GZip (can't compress folder, only file)
      r - use RAR
      7 - use 7z

  Examples:
    tcomp z '/home/alex/The Lord of the Rings.txt'  # creates '/home/alex/The Lord of the Rings.txt.zip'
    tcomp /home/alex/Hobbit.txt.7z                  # creates /home/alex/Hobbit.txt
  }
end

.testObject



43
44
45
46
47
48
49
50
51
# File 'lib/total_compressor.rb', line 43

def test
  result = []
  compressors = constants
  compressors -= [:BaseCompressor, :VERSION]
  compressors.each do |compressor|
    result << eval("TotalCompressor::#{compressor.to_s}.new.test")
  end
  result
end