Method: Unpack#initialize

Defined in:
lib/unpack.rb

#initialize(args) ⇒ Unpack

Returns a new instance of Unpack.

Raises:

  • (Exception)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/unpack.rb', line 8

def initialize(args)
  args.keys.each { |name| instance_variable_set "@" + name.to_s, args[name] }
  
  @options = {
    :min_files              => 5,
    :depth                  => 2,
    :debugger               => false,
    :force_remove           => false,
    :remove                 => false,
    :to                     => false,
    :absolute_path_to_unrar => "#{File.dirname(__FILE__)}/../bin/unrar"
  }
  
  @removeable = {}
  
  @options.merge!(args[:options]) if args[:options]
  
  # If the path is relative
  @directory = File.expand_path(@directory) unless @directory.match(/^\//)
  
  # Makes shure that every directory structure looks the same
  @directory = Dir.new(@directory).path rescue nil
  
  raise Exception.new("You need to specify a valid path") if @directory.nil? or not system("test -r '#{@directory}'")
  raise Exception.new("You need unzip to keep going") if %x{whereis unzip}.empty?
  
  @files = []
end