class RBT::Action::FilterForValidProgramNames

Public Class Methods

[](i = ARGV) click to toggle source
#

RBT::Action::FilterForValidProgramNames[]

#
# File lib/rbt/actions/individual_actions/filter_for_valid_program_names/filter_for_valid_program_names.rb, line 137
def self.[](i = ARGV)
  new(i)
end
new( i = ARGV, run_already = true, &block ) click to toggle source
#

initialize

#
# File lib/rbt/actions/individual_actions/filter_for_valid_program_names/filter_for_valid_program_names.rb, line 27
def initialize(
    i           = ARGV,
    run_already = true,
    &block
  )
  reset
  set_commandline_arguments(i)
  case run_already
  # ======================================================================= #
  # === :do_not_run_yet
  # ======================================================================= #
  when :do_not_run_yet
    run_already = false
  end
  run if run_already
end

Public Instance Methods

filter_for_valid_program_names( i = first?, dataset_containing_the_abbreviations = RBT.file_abbreviations, get_rid_of_unwanted_characters = true ) click to toggle source
#

filter_for_valid_program_names

#
# File lib/rbt/actions/individual_actions/filter_for_valid_program_names/filter_for_valid_program_names.rb, line 55
def filter_for_valid_program_names(
    i                                    = first?,
    dataset_containing_the_abbreviations = RBT.file_abbreviations,
    get_rid_of_unwanted_characters       = true
  )
  if i.is_a? Array
    i = i.first
  end
  i = i.dup
  i = remove_archive_from_the_end(i)
  if dataset_containing_the_abbreviations.is_a?(String) and
    File.exist?(dataset_containing_the_abbreviations)
    dataset_containing_the_abbreviations = 
      YAML.load_file(dataset_containing_the_abbreviations)
  end
  i.delete!(N) if i.include? N # Get rid of "\n".
  # ======================================================================= #
  # i.delete!('.') if i.include? '.' # Get rid of ".".
  # ^^^ The above line was deleted at 25.02.2022 because we may
  # also give "foobar-1.0.tar.xz" as input. If we then delete
  # '.' the net result is evidently incorrect.
  # ======================================================================= #
  if get_rid_of_unwanted_characters
    # ===================================================================== #
    # === Get rid of .yml, .pc and .md substrings
    # ===================================================================== #
    i.delete_suffix!('.yml') if i.end_with? '.yml'
    i.delete_suffix!('.pc')  if i.end_with? '.pc'
    i.delete_suffix!('.md')  if i.end_with? '.md'
    i.delete!(':') if i.include? ':'
    i.delete!('?') if i.include? '?'
    # ===================================================================== #
    # The next line can cause problems. I realised this in September 2022
    # when I did input "simple-scan@42.5". I would lose information,
    # which is bad, so the next line was commented out. This comment
    # should be preserved, in case I forget this.
    # ===================================================================== #
    # i.delete!('-') if i.include? '-'
    i.chop! if i.end_with? '.'
  end
  i.strip!
  # ======================================================================= #
  # Use some exceptions for "kde1" and "mate1", which will be
  # used in the next Array:
  # ======================================================================= #
  this_array = ARRAY_SPECIAL_COMPONENT_CONTAINING_MANY_SUBCOMPONENTS
  if i.respond_to?(:start_with?) and
     i.start_with?(*this_array) and 
    (i =~ /\d{1,4}$/) and
    !is_included?(i) # ← We have to prioritize on any registered program here.
    # ===================================================================== #
    # Next we will consider passing this into a special case/when menu
    # which will replace input such as "gnome1" with the corresponding
    # entry from the Array containing all gnome programs.
    # ===================================================================== #
    i = try_to_return_a_special_compile_component("--#{i}")
  else
    if !is_included?(i) and dataset_containing_the_abbreviations.has_key?(i)
      i = dataset_containing_the_abbreviations[i]
    end
  end
  @result = i
  return i
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Action#reset
# File lib/rbt/actions/individual_actions/filter_for_valid_program_names/filter_for_valid_program_names.rb, line 47
def reset
  super()
  infer_the_namespace
end
result?() click to toggle source
#

result?

#
# File lib/rbt/actions/individual_actions/filter_for_valid_program_names/filter_for_valid_program_names.rb, line 123
def result?
  @result
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/actions/individual_actions/filter_for_valid_program_names/filter_for_valid_program_names.rb, line 130
def run
  filter_for_valid_program_names(first?)
end