class ProgramInformation::ProgramInformation

Constants

APOSTROPH
#

APOSTROPH

#
BE_VERBOSE
#

BE_VERBOSE

#
COLOUR_FOR_REVERT
#

COLOUR_FOR_REVERT

#
DEFAULT_VERSION
LAST_UPDATE
#

LAST_UPDATE

#
NAME_OF_CLASS
#

NAME_OF_CLASS

#
REMOVE_PLUS_AND_MINUS
#

REMOVE_PLUS_AND_MINUS

If true then we will remove plus ‘+’ and minus ‘-’ from the program name.

#
REMOVE_PLUS_TOKEN
#

REMOVE_PLUS_TOKEN

If this constant is true then we will eliminate ‘+’ in the input.

This overrules the replace-constant called REPLACE_PLUS_WITH_LONG_NAME.

Also note that if the constant REMOVE_PLUS_AND_MINUS is set to true then this setting here will always be set to false.

#
REPLACE_PLUS_WITH_LONG_NAME
#

REPLACE_PLUS_WITH_LONG_NAME

If this constant is true then we will replace all ‘+’ with the string ‘plus’ as part of the issued name. Note that remove-actions are stronger, so if the constant REMOVE_PLUS_AND_MINUS was also set to true, then the constant here will not be honoured at all.

#
SHALL_WE_DOWNCASE
#

SHALL_WE_DOWNCASE

So that input such as “Libgnome” can become “libgnome”.

#
VERSION
#

VERSION

#

Public Class Methods

new( i = ARGV, run_already = true, optional_be_verbose = false ) click to toggle source
#

initialize

Specific Usage Example:

ProgramInformation::ProgramInformation.new('util-linux-ng-2.15')
#
# File lib/program_information/initialize.rb, line 15
def initialize(
    i                   = ARGV,
    run_already         = true,
    optional_be_verbose = false
  )
  reset
  set_input(i)
  if optional_be_verbose
    set_be_verbose(optional_be_verbose)
  end
  case run_already
  when :do_run_already
    run_already = true
  when :dont_run_already, :do_not_run_already
    run_already = false
  end
  run if run_already
end

Public Instance Methods

apostroph?() click to toggle source
#

apostroph?

#
# File lib/program_information/program_information.rb, line 153
def apostroph?
  APOSTROPH
end
array?()
Alias for: return_array
be_verbose?() click to toggle source
#

be_verbose?

#
# File lib/program_information/program_information.rb, line 115
def be_verbose?
  @be_verbose
end
determine_name_and_program_version(i = @input)
determine_the_three_main_variables(i = @input) click to toggle source
#

determine_the_three_main_variables

This method will determine the three main instance variables:

- @short_name
- @real_short_name
- @program_version

We must be careful, as the input may not include any ‘-’ or ‘_’ token, and then the regex would fail. Hence, the behaviour of this method will depend on whether the input includes a ‘-’ or whether it does not.

Note that presently, set_input() will modify the given input and ensure that there will be a ‘-’ token, even in input that does not have any ‘-’ or ‘_’ such as in ‘sendmail.8.15.2’.

#
# File lib/program_information/program_information.rb, line 307
def determine_the_three_main_variables(i = @input)
  if i
    if i.include? '|'
      splitted        = i.split('|')
      short_name      = splitted.first.to_s.dup
      program_version = splitted.last.to_s.dup
      set_short_name(short_name)
      set_program_version(program_version)
    else
      opn; e "The input `#{i}` does not include a | character."
    end
  end
end
do_not_downcase() click to toggle source
#

do_not_downcase

#
# File lib/program_information/program_information.rb, line 272
def do_not_downcase
  @shall_we_downcase = false
end
do_not_replace_anything()
Alias for: do_not_replace_plus
do_not_replace_plus() click to toggle source
#

do_not_replace_plus

#
# File lib/program_information/program_information.rb, line 71
def do_not_replace_plus
  @replace_plus_with_long_name = false
end
Also aliased as: do_not_replace_anything
e(i = '') click to toggle source
#

e

#
# File lib/program_information/program_information.rb, line 399
def e(i = '')
  ::ProgramInformation.e(i)
end
first()
Alias for: short_name?
input?() click to toggle source
#

input?

#
# File lib/program_information/program_information.rb, line 129
def input?
  @input
end
last()
Alias for: program_version?
last?()
Alias for: program_version?
menu(i) click to toggle source
#

menu (menu tag)

#
name()
Alias for: short_name?
name?()
Alias for: short_name?
name_of_the_program?()
Alias for: real_short_name?
program_name()
Alias for: short_name?
program_name?()
Alias for: short_name?
program_version()
Alias for: program_version?
program_version?() click to toggle source
#

program_version?

Getter method for the @program_version variable.

#
# File lib/program_information/program_information.rb, line 439
def program_version?
  @program_version
end
real_name?()
Alias for: real_short_name?
real_program_name?()
Alias for: real_short_name?
real_short_name()
Alias for: real_short_name?
real_short_name?() click to toggle source
#

real_short_name?

Keep in mind that @real_short_name does not have any ‘-’ tokens.

#
# File lib/program_information/program_information.rb, line 408
def real_short_name?
  @real_short_name
end
remove_archive_type(i) click to toggle source
#

remove_archive_type

#
# File lib/program_information/program_information.rb, line 391
def remove_archive_type(i)
  ::ProgramInformation.remove_archive_type(i)
  return i
end
remove_file_suffix(i) click to toggle source
#

remove_file_suffix

Delegate towards class RemoveFileSuffix. This is easier to handle Archive.

#
# File lib/program_information/program_information.rb, line 64
def remove_file_suffix(i)
  RemoveFileSuffix[i.to_s]
end
remove_plus_and_minus()
remove_plus_and_minus?() click to toggle source
#

remove_plus_and_minus?

#
# File lib/program_information/program_information.rb, line 146
def remove_plus_and_minus?
  @remove_plus_and_minus
end
Also aliased as: remove_plus_and_minus
remove_plus_token?() click to toggle source
#

remove_plus_token?

#
# File lib/program_information/program_information.rb, line 122
def remove_plus_token?
  @remove_plus_token
end
remove_source_like_strings(i) click to toggle source
#

remove_source_like_strings

#
# File lib/program_information/program_information.rb, line 377
def remove_source_like_strings(i)
  # ======================================================================= #
  # i.gsub!(/--/,'-') if i.include? '--' # Replace '--' with '-'.
  # ^^^ May not be good, depending on the input.
  # ======================================================================= #
  i.sub!(/-src/,'')     if i.include?  '-src' # Get rid of -src entries.
  i.sub!(/\.source/,'') if i.include?  '.source'
  i.sub!(/-source$/,'') if i.end_with? '-source'
  return i
end
replace_plus_with_long_name?() click to toggle source
#

replace_plus_with_long_name?

#
# File lib/program_information/program_information.rb, line 160
def replace_plus_with_long_name?
  @replace_plus_with_long_name
end
report( be_verbose = be_verbose? ) click to toggle source
#

report (debug tag, report tag)

#
# File lib/program_information/report.rb, line 12
def report(
    be_verbose = be_verbose?
  )
  case be_verbose
  when :do_report, :be_verbose
    be_verbose = true
  end
  lpad = 90
  rpad = 49
  if be_verbose
    inner_ljust = 28
    # ===================================================================== #
    # === real short name
    # ===================================================================== #
    e (NAME_OF_CLASS+(' Program real short name ').ljust(inner_ljust)+'('+
      yellow?+'@real_short_name'+rev+') is: ').ljust(lpad)+
      (apostroph?+real_short_name?+apostroph?).
      ljust(rpad)
    # ===================================================================== #
    # === short name
    # ===================================================================== #
    e (
      NAME_OF_CLASS+(' Program name').ljust(inner_ljust)+'('+
      yellow?+'@short_name'+rev+'     ) is: '
    ).ljust(lpad)+(apostroph?+short_name?+apostroph?).
      ljust(rpad)
    # ===================================================================== #
    # === program version
    # ===================================================================== #
    e (NAME_OF_CLASS+(' Program version ').ljust(inner_ljust)+'('+
      yellow?+'@program_version'+rev+') is: ').ljust(lpad)+
      (apostroph?+version?+apostroph?).
      ljust(rpad)
  end
end
Also aliased as: report_result
report_result( be_verbose = be_verbose? )
Alias for: report
reset() click to toggle source
#

reset

#
# File lib/program_information/reset.rb, line 14
def reset
  # ======================================================================= #
  # === @short_name
  # ======================================================================= #
  @short_name      = nil
  # ======================================================================= #
  # === @real_short_name
  # ======================================================================= #
  @real_short_name = nil
  # ======================================================================= #
  # === @program_version
  # ======================================================================= #
  @program_version = nil
  set_shall_we_downcase # Should become before set_input().
  set_be_verbose
  # ======================================================================= #
  # === @remove_plus_and_minus
  # ======================================================================= #
  @remove_plus_and_minus = REMOVE_PLUS_AND_MINUS
  # ======================================================================= #
  # === @replace_plus_with_long_name
  # ======================================================================= #
  @replace_plus_with_long_name = REPLACE_PLUS_WITH_LONG_NAME
  @remove_plus_token = REMOVE_PLUS_TOKEN
  if @remove_plus_and_minus # Overrule always in this case.
    @replace_plus_with_long_name = false
  end
  if @remove_plus_and_minus
    @remove_plus_token = false
  end
end
return_array() click to toggle source
#

return_array

This method will return a composite, 3-member Array that will hold the short_name, the real_short_name, and the program_version.

#
# File lib/program_information/program_information.rb, line 139
def return_array
  [ short_name?, real_short_name?, program_version? ]
end
Also aliased as: array?
return_name()
Alias for: short_name?
return_name_and_version(i = nil) click to toggle source
#

return_name_and_version

This method will return an array with two elements:

(1) The first element is the name of the program in question.
(2) The second element is the version of the program in question.

The input can be rather tricky and complicated.

Consider the following examples:

'libunwind-1.0-rc1'
'htop-1.0.0'
'WebKit-r93670'
'xfce4-dev-tools-4.8.0'
'e_dbus-1.7.10.tar.gz'
'boost_1_54_0.tar.bz2'
'short-mime-1.0.0-rc1'

This can all be valid input.

Which are the key-assumptions that we can do here?

I think the best assumption we can do is to find the first NUMBER in the given string, and then group the rest of the data according to this NUMBER. This will not work in the case of something such as WebKit-r93, as there is a ‘r’ character before that number. So we will have to make a second assumption: if the character preceding the first found integer is NOT a ‘-’ character, we will instead split on that character instead. This will however lead to a problem for something like “xfce4-dev-tools-4.8.0”. So, in case there is a ‘-’ character immediately after the pos variable, we assume we have such a special case.

On Sep 2011, I came up with a far simpler idea. We simply have to find the most important ‘-’ and then split accordingly. As long as we can identify the most important ‘-’ correctly, so long will everything else “just work”. This also did not work out, so I switched to a regex instead. Since then it has worked very fine.

Take input such as:

"font-bitstream-75dpi-1.0.0"

Note though that this approach does not work with input like:

"CrownCutlass-Alpha1.4"

unless we assume that alpha is a part of the version, which is possibly correct.

#
# File lib/program_information/program_information.rb, line 243
def return_name_and_version(i = nil)
  if i
    determine_the_three_main_variables(i)
  end
  # ======================================================================= #
  # We must consider what we wish to do about the '_' characters. We could
  # remove them, but certain programs such as e_dbus may require it as
  # part of their name. Also, Version entries such as '1_2_3' will become
  # '123' rather than '1.2.3'. Thus, on Jan 2014 I have disabled the
  # following line.
  # ======================================================================= #
  # i.delete!('_') if i.include? '_'
  return [
    @short_name, @program_version
  ]
end
Also aliased as: rnav
return_program_real_name()
Alias for: short_name?
return_proper_pipe_token_to_this_input(i) click to toggle source
#

return_proper_pipe_token_to_this_input

#
# File lib/program_information/program_information.rb, line 54
def return_proper_pipe_token_to_this_input(i)
  ::ProgramInformation.return_proper_pipe_token_to_this_input(i)
end
return_real_short_name_and_version(i) click to toggle source
#

return_real_short_name_and_version

We delegate to the module-method here.

#
# File lib/program_information/program_information.rb, line 189
def return_real_short_name_and_version(i)
  ::ProgramInformation.return_real_short_name_and_version(i)
end
return_short_name()
Alias for: short_name?
rev() click to toggle source
#

rev

#
# File lib/program_information/constants/colours.rb, line 16
def rev
  Colours.rev
end
rnav(i = nil)
run() click to toggle source
#

run

#
# File lib/program_information/run.rb, line 14
def run
  determine_the_three_main_variables
end
set_be_verbose(i = BE_VERBOSE) click to toggle source
#

set_be_verbose

Set to report in a verbose way here.

#
# File lib/program_information/program_information.rb, line 281
def set_be_verbose(i = BE_VERBOSE)
  case i
  when :be_verbose
    i = true
  end
  @be_verbose = i
end
set_input(i) click to toggle source
#

set_input

This method will, after performing some sanitize-operations, assign to the @input variable.

#
# File lib/program_information/program_information.rb, line 454
def set_input(i)
  if i.is_a? Array
    menu(i)
    i = i.join(' ').strip
  end
  i = i.to_s.dup if i.frozen?
  i = File.basename(i)
  # ======================================================================= #
  # We .squeeze away '--' tokens.
  # ======================================================================= #
  i.squeeze!('-')
  i.strip!
  # ======================================================================= #
  # Next, some simple replacements without any method.
  # ======================================================================= #
  i.sub!(/-paco/,'')        if i.include? '-paco'
  i.sub!(/\/Programs\//,'') if i.include? '/Programs'
  # ======================================================================= #
  # The following must not conflict with i.e. "pkgconfig", hence why we
  # also include a '/' character.
  # ======================================================================= #
  i.gsub!(/\/pkg/,'') if i.include? '/pkg'
  # ======================================================================= #
  # i.gsub!(/\//,'-') # Controversial. Disabled for now as of Jan 2014.
  # ======================================================================= #
  # We don't want either { or }.
  # ======================================================================= #
  i.delete!('{') if i.include? '{'
  i.delete!('}') if i.include? '}'
  # ======================================================================= #
  # As of July 2016, we get rid of all tokens that follow a '#' character.
  # We also will get rid of the '#' as well. Must come before we call
  # remove_archive_type().
  # ======================================================================= #
  if i.include? '#'
    i = i[0...i.index('#')]
  end
  i = remove_archive_type(i)
  i = remove_source_like_strings(i)
  # ======================================================================= #
  # Next, we correct for input such as "nana%201.5.4". This one has no
  # '-' token and no '_' token, but a '%' token. This '%' token will be
  # replaced.
  # ======================================================================= #
  if i.include? '%'
    unless i.include?('_') or i.include?('-')
      i.tr!('%','-')
    end
  end
  # ======================================================================= #
  # Leading '-' will be removed.
  # ======================================================================= #
  i[0,1] = '' if i.start_with? '-'
  # ======================================================================= #
  # === Handle downcasing of the given input
  #
  # This will consider downcasing the input. The reason as to why this is
  # necessary is so that input such as "Libgnome" can become "libgnome".
  # ======================================================================= #
  i.downcase! if @shall_we_downcase
  # ======================================================================= #
  # === Handle '+' tokens
  # ======================================================================= #
  if REMOVE_PLUS_TOKEN
    i.delete!('+') if i.include? '+'
  end
  i = return_proper_pipe_token_to_this_input(i)
  @input = i
end
set_name(i)
Alias for: set_short_name
set_name_then_version(a, b)
set_program_name(i)
Alias for: set_short_name
set_program_version(i) click to toggle source
#

set_program_version

Use this method whenever you wish to assign to the @program_version variable.

The input to this method may include stuff such as “.tar.xz”, which should be chopped off, as it is not part of the program version.

Keep in mind that we may also return nil.

Until March 2015 we also replaced all ‘_’ with ‘.’ characters, but input such as “ncbi_cxx–12_0_0.tar.gz” would break as a consequence, so this was disabled again.

#
# File lib/program_information/program_information.rb, line 90
def set_program_version(i)
  i = remove_file_suffix(i) unless i.nil? # Disallow archive-types here.
  # ======================================================================= #
  # The following check is not good at all because we may have input
  # such as "1-0.112.0". Polkitqt has this, for instance.
  # Thus, the following line was disabled on Feb 2016.
  # ======================================================================= #
  # if i.include? '-' # In this case, we use only the last part.
  #   i = i.split('-').last
  # end
  # ======================================================================= #
  # And if result is actually an empty String, but the original input
  # has included at the least one number, such as in "3.3.6-pl1",
  # then we will simply use that instead.
  # ======================================================================= #
  if i.is_a?(String) and i.empty? and
     @input =~ /\d+/ # <- If the input has at the least one Number.
    i = @input.dup
  end
  @program_version = i
end
Also aliased as: set_version
set_real_short_name(i = @short_name) click to toggle source
#

set_real_short_name

The instance variable @real_short_name is not allowed to include any ‘-’ characters. It may also not include any ‘_’ characters.

The latter could be found as part of program names such as “SDL_image”. The @short_name variant may include these ‘_’ tokens.

Note that as of September 2017, we also disallow ‘.’ tokens, such as may occur accidentally in input like “sendmail.5.8.2”.

#
# File lib/program_information/program_information.rb, line 333
def set_real_short_name(i = @short_name)
  i = i.to_s.dup.delete('-_.').rstrip
  @real_short_name = i
end
set_shall_we_downcase( i = SHALL_WE_DOWNCASE ) click to toggle source
#

set_shall_we_downcase

#
# File lib/program_information/program_information.rb, line 263
def set_shall_we_downcase(
    i = SHALL_WE_DOWNCASE
  )
  @shall_we_downcase = i
end
set_short_name(i) click to toggle source
#

set_short_name

Use this method whenever you wish to assign to the @short_name variable.

This variable is allowed to keep ‘-’ and ‘_’ entries, but some settings may also modify this.

#
# File lib/program_information/program_information.rb, line 346
def set_short_name(i)
  i = i.dup
  # ======================================================================= #
  # First, consider getting rid of '+' and '-' tokens in the
  # @short_name variant of the program name.
  # For this to work, @remove_plus_and_minus has to be set to true.
  # ======================================================================= #
  if remove_plus_and_minus?
    i.delete!('+') if i.include? '+'
    i.delete!('-') if i.include? '-'
  end
  # ======================================================================= #
  # === Get rid of '+' tokens, if they are included.
  # ======================================================================= #
  if remove_plus_token?
    i.delete!('+') if i.include? '+'
  # ======================================================================= #
  # === Alternatively, replace '+' with the string 'plus' should it
  # exist there.
  # ======================================================================= #
  elsif replace_plus_with_long_name?
    i.gsub!(/\+/, 'plus') if i.include? '+'
  end
  @short_name = i
  set_real_short_name(i) # We will also sync towards @real_short_name.
end
Also aliased as: set_name, set_program_name
set_short_name_then_version(a, b) click to toggle source
#

set_short_name_then_version

This method will combine two other methods.

#
# File lib/program_information/program_information.rb, line 179
def set_short_name_then_version(a, b)
  set_short_name(a)
  set_program_version(b)
end
Also aliased as: set_name_then_version
set_version(i)
Alias for: set_program_version
short_name()
Alias for: short_name?
short_name?() click to toggle source
#

short_name?

Reader method for the @short_name instance variable.

short_name is an alias to @short_name.

#
# File lib/program_information/program_information.rb, line 422
def short_name?
  @short_name
end
short_name_and_version()
short_name_and_version?() click to toggle source
#

short_name_and_version?

This method returns an aggregated @short_name+‘-’+@program_version string.

#
# File lib/program_information/program_information.rb, line 170
def short_name_and_version?
  "#{short_name?}-#{program_version?}"
end
Also aliased as: short_name_and_version
show_help() click to toggle source
#

show_help (help tag)

To invoke this method, try:

pinfo --show-help
#
# File lib/program_information/program_information.rb, line 532
def show_help
  e
  e 'This class is able to split a given input (a string) into'
  e 'the inferred program-name, and associated program version '\
    'of said string.'
  e
  e 'For example, if you have this input string:'
  e
  e '  gobject-introspection-1.52.1'
  e
  e 'then this class can split this into these constituents:'
  e
  e '  @real_short_name: gobjectintrospection'
  e '  @short_name:      gobject-introspection'
  e '  @program_version: 1.52.1'
  e
  e 'This is especially useful for other projects that require this'
  e 'functionality, such as the rbt gem.'
  e
end
version()
Alias for: program_version?
version?()
Alias for: program_version?
version_of_the_program?()
Alias for: program_version?
yellow?() click to toggle source
#

yellow?

#
# File lib/program_information/constants/colours.rb, line 38
def yellow?
  Colours::BOLD_YELLOW
end