module Extracter

#

Extracter::Base

This is the base class for the extracter-gem.

Usage example:

Extracter::Base.new(ARGV)
#

require ‘extracter/base/base.rb’; < ::Extracter::Base

#
#

require ‘extracter/constants/constants.rb’

#
#

require ‘extracter/toplevel_methods/is_this_a_valid_archive.rb’ Extracter.is_this_a_valid_archive?

#
#

require ‘extracter/version/version.rb’

#

Constants

ARRAY_REGISTERED_ARCHIVES
#

Extracter::ARRAY_REGISTERED_ARCHIVES

Archives that can be extracted, have to be registered in this Array.

This Array has to be sorted alphabetically.

The libreoffice format .odt is just like .zip.

#
COMMAND_TO_EXTRACT_BSDTAR_ARCHIVES
#

COMMAND_TO_EXTRACT_BSDTAR_ARCHIVES

This command is to specifically extract rpm-archives.

#
COMMAND_TO_EXTRACT_DEB_FILES
#

COMMAND_TO_EXTRACT_DEB_FILES

#
COMMAND_TO_EXTRACT_JAR_ARCHIVES
#

COMMAND_TO_EXTRACT_JAR_ARCHIVES

#
COMMAND_TO_EXTRACT_LZMA_FILES
#

COMMAND_TO_EXTRACT_LZMA_FILES

#
COMMAND_TO_EXTRACT_LZ_FILES
#

COMMAND_TO_EXTRACT_LZ_FILES

#
COMMAND_TO_EXTRACT_TAR_BZ2_FILES
#

COMMAND_TO_EXTRACT_TAR_BZ2_FILES

#
COMMAND_TO_EXTRACT_TAR_FILES
#

COMMAND_TO_EXTRACT_TAR_FILES

#
COMMAND_TO_EXTRACT_TAR_XZ_FILES
#

COMMAND_TO_EXTRACT_TAR_XZ_FILES

#
COMMAND_TO_EXTRACT_TGZ_FILES
#

COMMAND_TO_EXTRACT_TGZ_FILES

This is specifically for .tgz files.

#
COMMAND_TO_EXTRACT_ZST_ARCHIVES
#

COMMAND_TO_EXTRACT_ZST_ARCHIVES

#
GEM_UNPACK_COMMAND
#

GEM_UNPACK_COMMAND

The command to use to unpack ruby .gems.

We can pass the —target=DIR syntax to extract to a specific location.

#
LAST_UPATE
#

LAST_UPDATE

#
N
#

N

#
SECOND_UNPACK_COMMAND_TO_USE_ON_WINDOWS
#

SECOND_UNPACK_COMMAND_TO_USE_ON_WINDOWS

#
TEMP_DIR
#

If this environment variable is unavailable then use a conservative default value.

#
UNPACK_COMMAND_TO_USE_ON_WINDOWS
#

UNPACK_COMMAND_TO_USE_ON_WINDOWS

The full commandline when on windows will look like this:

7z x -so C:\home\x\src\htop\htop-3.0.5.tar.xz | 7z x -si -ttar

This was used in the RBT project, in the past, e. g. via code such as:

cmd = '7z x "'.dup
cmd << i
cmd << '" -so | 7z x -aoa -si -ttar -o"'+program_name_and_program_version?.to_s+'"'
#
VERSION
#

VERSION

Which specific version to use for class Extracter.

#

Public Class Methods

are_we_on_windows?() click to toggle source
#

Extracter.are_we_on_windows?

This method can be used to determine whether we are on windows (as our primary platform) or whether we are not.

#
# File lib/extracter/toplevel_methods/toplevel_methods.rb, line 25
def self.are_we_on_windows?
  RUBY_PLATFORM.include?('win') or
  RUBY_PLATFORM.include?('mingw')
end
esystem(i) click to toggle source
#

Extracter.esystem

#
# File lib/extracter/toplevel_methods/toplevel_methods.rb, line 44
def self.esystem(i)
  puts i
  system(i)
end
extract_what_to( what = ARGV, extract_to = :default, run_already = true, &block ) click to toggle source
#

Extracter.extract_what_to

Useage example goes like this:

Extracter.extract_what_to('foo-1.0.tar.xz', '/tmp')
Extracter.extract_what_to('/Depot/jjjj/tesseract-5.1.0.tar.xz', Dir.pwd+'/')
#
# File lib/extracter/class/extracter.rb, line 1193
def self.extract_what_to(
    what        = ARGV,
    extract_to  = :default, # ← This can also be a Hash. It denotes where we want to extract to.
    run_already = true, # :do_not_run_yet,
    &block
  )
  _ = ::Extracter::Extracter.new(
        what,
        extract_to,
        run_already,
        &block
      )
  return _ # We must return the class, as other projects may depend on this.
end
is_this_a_valid_archive?( i, array_registered_archives = ARRAY_REGISTERED_ARCHIVES ) click to toggle source
#

Extracter.is_this_a_valid_archive?

Query whether the input given to this method is a valid archive.

This allows us to determine whether the Extracter project can deal with the given archive at hand or whether it can not.

The registered formats are stored in the constant ARRAY_REGISTERED_ARCHIVES.

#
# File lib/extracter/toplevel_methods/toplevel_methods.rb, line 75
def self.is_this_a_valid_archive?(
    i, # The given input, such as "foobar.zip".
    array_registered_archives = ARRAY_REGISTERED_ARCHIVES
  )
  if i.is_a? Array
    i = i.first
  end
  return_value = false
  array_registered_archives.each {|entry|
    return_value = true if i =~ /#{entry}$/i
  }
  return return_value
end
remove_archive_type(i) click to toggle source
#

Extracter.remove_archive_type

This method will remove suffix-types from a given input String.

#
# File lib/extracter/toplevel_methods/toplevel_methods.rb, line 54
def self.remove_archive_type(i)
  return i.delete_suffix('.xz').
           delete_suffix('.tgz').
           delete_suffix('.bz2').
           delete_suffix('.gz').
           delete_suffix('.tar').
           delete_suffix('.zip').
           delete_suffix('.gem')
end
return_pwd() click to toggle source
#

Extracter.return_pwd

#
# File lib/extracter/toplevel_methods/toplevel_methods.rb, line 15
def self.return_pwd
  "#{Dir.pwd}/".squeeze('/')
end
this_on_windows(i) click to toggle source
#

Extracter.are_we_on_windows?

#
# File lib/extracter/toplevel_methods/toplevel_methods.rb, line 33
def self.this_on_windows(i)
  _ = UNPACK_COMMAND_TO_USE_ON_WINDOWS+' '+
      File.absolute_path(i)+
      ' | '+
      SECOND_UNPACK_COMMAND_TO_USE_ON_WINDOWS
  esystem _
end