Class: Chrysalis::Ar::ZipArchive

Inherits:
Chrysalis::Archive show all
Defined in:
lib/chrysalis/ar/zip.rb

Overview

Implements support for extracting ZIP archives.

Archives of this type are identified by the file extension .zip.

Constant Summary collapse

EXTENSION =
".zip".freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Chrysalis::Archive

extract, inherited

Constructor Details

#initialize(path, params = {}) ⇒ ZipArchive

Returns a new instance of ZipArchive.



19
20
21
22
23
24
# File 'lib/chrysalis/ar/zip.rb', line 19

def initialize(path, params = {})
  super
  @extract_to = params[:extract_to]
  @extracts_into = params[:extracts_into]
  @noop = params[:noop]
end

Class Method Details

.extracts?(path) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/chrysalis/ar/zip.rb', line 15

def self.extracts?(path)
  path.end? EXTENSION
end

Instance Method Details

#extract(to = '.') ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/chrysalis/ar/zip.rb', line 26

def extract(to = '.')
  dir = Pathname.new(to)
  dir = dir + @extract_to if @extract_to
  
  unless @noop
    puts "Extracting #{@path} ..."
    sh "unzip #{@path} -d #{dir.cleanpath}"
  end
  
  ex_path = Pathname.new(dir).join(extracts_into)
  ex_path.cleanpath.to_s
end