Class: Suvii::Extract

Inherits:
Object
  • Object
show all
Defined in:
lib/suvii/extract.rb,
lib/suvii/extract/zip.rb,
lib/suvii/extract/targz.rb

Overview

Since:

  • 0.1.0

Direct Known Subclasses

Targz, Zip

Defined Under Namespace

Classes: Targz, Zip

Constant Summary collapse

UnknownFormatError =

Since:

  • 0.1.0

Class.new(StandardError)
TARGZ_RE =

Since:

  • 0.1.0

/\.t(ar\.)?gz\z/
ZIP_RE =

Since:

  • 0.1.0

/\.zip\z/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, options = {}) ⇒ Extract

Returns a new instance of Extract.

Parameters:

  • source (String)

    local path to an archive.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :strip_components (Integer) — default: nil, i.e. no skipping

    specifies number of top-level directories to be skipped during the archive extraction. Same as ‘strip-components` option for GNU tar.

Since:

  • 0.1.0



31
32
33
34
# File 'lib/suvii/extract.rb', line 31

def initialize(source, options = {})
  @source = source
  @strip_components = options[:strip_components]
end

Instance Attribute Details

#sourceString (readonly)

Returns:

  • (String)

Since:

  • 0.1.0



22
23
24
# File 'lib/suvii/extract.rb', line 22

def source
  @source
end

#strip_componentsInteger? (readonly)

Returns:

  • (Integer, nil)

Since:

  • 0.1.0



25
26
27
# File 'lib/suvii/extract.rb', line 25

def strip_components
  @strip_components
end

Class Method Details

.class_for(source) ⇒ Targz, Zip

Detects proper class for given archive path.

Parameters:

  • source (String)

    local path to an archive.

Returns:

Raises:

Since:

  • 0.1.0



13
14
15
16
17
18
19
# File 'lib/suvii/extract.rb', line 13

def self.class_for(source)
  case source
  when TARGZ_RE then Targz
  when ZIP_RE then Zip
  else raise UnknownFormatError, "unknown format for #{source}"
  end
end

Instance Method Details

#extract_to(destination) ⇒ String

Performs archive extraction.

Parameters:

  • destination (String)

    directory where the archive should be extracted.

Returns:

  • (String)

    destination.

Raises:

  • (NotImplementedError)

Since:

  • 0.1.0



40
41
42
# File 'lib/suvii/extract.rb', line 40

def extract_to(destination)
  raise NotImplementedError
end