class RBT::Cookbooks::Aliases

Public Class Methods

new( this_program = DEFAULT_PROGRAM_ENTRY, run_already = true ) click to toggle source
#

initialize

The first argument, ‘this_program`, will be assigned to the instance variable @this_program, which keeps track of our original input.

#
# File lib/rbt/aliases/aliases.rb, line 103
def initialize(
    this_program = DEFAULT_PROGRAM_ENTRY,
    run_already  = true
  )
  register_sigint
  reset
  set_search_for_this_program(
    this_program
  )
  run if run_already
end

Public Instance Methods

[](i = program_name?)
Alias for: points_at?
aliases?()
Alias for: available_programs?
available_programs()
Alias for: available_programs?
available_programs?() click to toggle source
#

avaiable_programs?

#
# File lib/rbt/aliases/aliases.rb, line 268
def available_programs?
  raw_aliases?.keys
end
data()
Alias for: dataset?
data?()
Alias for: dataset?
dataset()
Alias for: dataset?
dataset?() click to toggle source
#

dataset?

#
# File lib/rbt/aliases/aliases.rb, line 190
def dataset?
  @internal_hash[:dataset]
end
Also aliased as: dataset, data?, data
deep_show() click to toggle source
#

deep_show

This will show all matches. It is thought to be used in conjunction with a query (and obviously, the variable @is_included must be set for this to work.

#
# File lib/rbt/aliases/aliases.rb, line 232
def deep_show
  if is_included?
    opne "Additionally, also showing all aliases starting "\
         "with `#{sfancy(program?)}*`."
    all_matches = keys?.select {|key| key =~ /^#{program?}/ }
    e all_matches.sort.join(', ').split(N).map {|entry| '  '+entry }.join(N)
  end
end
Also aliased as: show_all_matches
enable_aliases() click to toggle source
#

enable_aliases

This method is required so that keys such as “qt4r” also work, which is an alias of “qt4ruby” pointing towards “qt4qtruby”.

This will, however had, only be done if the variable at @internal_hash is set to true.

#
# File lib/rbt/aliases/aliases.rb, line 283
def enable_aliases
  if @internal_hash[:use_abbreviations_for_the_aliases]
    _ = {} # This will become the new Hash.
    # ===================================================================== #
    # Iterate over the old aliases.
    # ===================================================================== #
    dataset?.each_pair {|key, value|
      _[key]   = value
      _[value] = value # Also keep itself as name.
      loop {
        # ================================================================= #
        # Get all but the last two characters repeatedly, so we chop up
        # the keys.
        # ================================================================= #
        key = key[0..-2]
        _[key] = value
        break if key.empty?
      }
    }
    set_dataset(_)
  end
end
expanded_name(i = program_name?)
Alias for: points_at?
find(i = program?) click to toggle source
#

find

find() will output in a verbose manner, regardless of the verbosity level.

#
# File lib/rbt/aliases/aliases.rb, line 217
def find(i = program?)
  if is_included?(i)
    opne '`'+sfancy(i)+'` matches towards `'+sfancy(points_at?(i))+'`.'
  else
    opne '`'+sfancy(i)+'` does not match to anything.'
  end
end
Also aliased as: show
found?(i = program_name?)
Alias for: is_included?
ihash?()
Alias for: internal_hash?
includes?(i = program_name?)
Alias for: is_included?
input?()
internal_hash?() click to toggle source
#

internal_hash?

#
# File lib/rbt/aliases/aliases.rb, line 379
def internal_hash?
  @internal_hash
end
Also aliased as: ihash?
is_a_real_alias?(i = input?) click to toggle source
#

is_a_real_alias?

This method tells us whether we have a real alias, that is originating from the initial Hash, or whether we have an alias that we deduced.

#
# File lib/rbt/aliases/aliases.rb, line 183
def is_a_real_alias?(i = input?)
  raw_aliases?.has_key? i
end
is_an_alias?(i = program_name?)
Alias for: is_included?
is_included?(i = program_name?) click to toggle source
#

is_included?

#
# File lib/rbt/aliases/aliases.rb, line 386
def is_included?(i = program_name?)
  dataset?.has_key? i
end
Also aliased as: is_an_alias?, includes?, found?, was_found?
keys()
Alias for: keys?
keys?() click to toggle source
#

keys

Assign the keys, then returns all keys. Will be sorted.

#
# File lib/rbt/aliases/aliases.rb, line 311
def keys?
  @internal_hash[:keys]
end
Also aliased as: keys
menu( i = search_for_which_program? ) click to toggle source
#

menu

#
n_entries?()
n_registered_aliases?() click to toggle source
#

n_registered_aliases?

#
# File lib/rbt/aliases/aliases.rb, line 150
def n_registered_aliases?
  @internal_hash[:raw_dataset].keys.size
end
n_registered_programs?()
obtain_dataset() click to toggle source
#

obtain_raw_dataset

#
# File lib/rbt/aliases/aliases.rb, line 430
def obtain_dataset
  # ======================================================================= #
  # The main pointer to point at our yaml data. This is a Hash.
  # ======================================================================= #
  set_dataset(
    RBT.cookbook_aliases? # Defined in rbt/aliases/aliases.rb
  )
  obtain_raw_dataset # Also sync at the raw dataset.
end
obtain_raw_dataset() click to toggle source
#

obtain_raw_dataset

#
# File lib/rbt/aliases/aliases.rb, line 396
def obtain_raw_dataset
  # ======================================================================= #
  # === :raw_dataset
  #
  # Keep a raw dataset, as reference copy. The raw dataset is the
  # unmodified set of key-value pairs.
  # ======================================================================= #
  @internal_hash[:raw_dataset] = @internal_hash[:dataset].dup
end
opnn() click to toggle source
#

opnn

#
Calls superclass method
# File lib/rbt/aliases/aliases.rb, line 143
def opnn
  super(namespace?)
end
points_at?(i = program_name?) click to toggle source
#

points_at?

Return the alias-pointer, without any additional checking whatsoever.

Note that [] is also available as alias.

#
# File lib/rbt/aliases/aliases.rb, line 248
def points_at?(i = program_name?)
  dataset?[i]
end
points_to?(i = program_name?)
Alias for: points_at?
program?()
program_name?()
programs?()
Alias for: available_programs?
raw_aliases?()
Alias for: raw_dataset?
raw_data?()
Alias for: raw_dataset?
raw_dataset?() click to toggle source
#

raw_dataset?

#
# File lib/rbt/aliases/aliases.rb, line 409
def raw_dataset?
  @internal_hash[:raw_dataset]
end
Also aliased as: raw_data?, raw_aliases?
real_alias(i = program_name?)
Alias for: points_at?
replace(i = program_name?)
Alias for: points_at?
report() click to toggle source
#

report

#
# File lib/rbt/aliases/aliases.rb, line 503
def report
  opne 'The available aliases are:'
  opne keys?.join(', ')
  opne 'The available datasets are:'
  pp data?
  opne "The total size of all available aliases-keys is "\
       "#{keys?.size} entries."
end
report_n_entries( i = n_entries? ) click to toggle source
#

report_n_entries

#
# File lib/rbt/aliases/aliases.rb, line 339
def report_n_entries(
    i = n_entries?
  )
  e
  opne 'We have n entries (== core aliases) registered:'
  opne "  #{sfancy(i)}"
  e
end
report_whether_the_input_is_an_alias(i = program?) click to toggle source
#

report_whether_the_input_is_an_alias

This method can be used to report whether the given input is an alias or whether it is not.

#
# File lib/rbt/aliases/aliases.rb, line 202
def report_whether_the_input_is_an_alias(i = program?)
  if is_included?(i)
    opne 'The program `'+sfancy(i)+'` is an alias, pointing '\
         'at the program `'+simp(points_at?)+'`.'
  else
    opne 'The program `'+sfancy(i)+'` is NOT an alias.'
  end
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method
# File lib/rbt/aliases/aliases.rb, line 118
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === :be_verbose
  # ======================================================================= #
  do_not_be_verbose # By default, we will be fairly quiet.
  # ======================================================================= #
  # === :use_abbreviations_for_the_aliases
  #
  # The next setting determines whether class Cookbooks::Aliases will
  # use abbreviations for its core-defined aliases. The core-defined
  # aliases are those that are written in the .yml file directly;
  # the abbreviations to these aliases, are NOT core aliases.
  #
  # By default, we will NOT use abbreviations - you have to specifically
  # enable this in your code if you want to use abbreviations.
  # ======================================================================= #
  @internal_hash[:use_abbreviations_for_the_aliases] = false
  obtain_dataset
end
result(i = program?)
Alias for: translate_alias
result?(i = program?)
Alias for: translate_alias
run() click to toggle source
#

run

#
# File lib/rbt/aliases/aliases.rb, line 515
def run
  enable_aliases
  set_keys
  menu
end
search_for_this_program?() click to toggle source
#

search_for_this_program?

#
# File lib/rbt/aliases/aliases.rb, line 158
def search_for_this_program?
  ihash?[:search_for_this_program]
end
search_for_which_program?()
set_dataset( i = RBT.cookbook_aliases? ) click to toggle source
#

set_dataset

This sets the main dataset. If you ever need the raw dataset, make use of the method called raw_dataset?. Note that this dataset will lateron become expanded via “aliases” to this dataset.

#
# File lib/rbt/aliases/aliases.rb, line 421
def set_dataset(
    i = RBT.cookbook_aliases?
  )
  @internal_hash[:dataset] = i
end
set_keys( i = dataset?.keys.sort ) click to toggle source
#

set_keys

This will keep track of how many keys there are in our dataset.

#
# File lib/rbt/aliases/aliases.rb, line 171
def set_keys(
    i = dataset?.keys.sort
  )
  @internal_hash[:keys] = i
end
set_search_for_this_program( i = DEFAULT_PROGRAM_ENTRY ) click to toggle source
#

set_search_for_this_program

This setter method will search for the given program at hand.

#
# File lib/rbt/aliases/aliases.rb, line 353
def set_search_for_this_program(
    i = DEFAULT_PROGRAM_ENTRY
  )
  i = i.first if i.is_a? Array
  i = DEFAULT_PROGRAM_ENTRY if i.nil?
  i = i.to_s.dup # To ensure that it is never nil.
  # ======================================================================= #
  # Remove all '_' characters since as of March 2012.
  # Disabled this again in August 2018 - let's see which variant
  # will be kept in the long run.
  # ======================================================================= #
  # i.delete!('-') if i.include? '-'
  ihash?[:search_for_this_program] = i
end
show(i = program?)
Alias for: find
show_all_abbreviations() click to toggle source
#

show_all_abbreviations

#
# File lib/rbt/aliases/aliases.rb, line 371
def show_all_abbreviations
  abbreviations = dataset?
  pp abbreviations
end
show_all_available_entriesx() click to toggle source
#

show_all_available_entries

#
# File lib/rbt/aliases/aliases.rb, line 318
def show_all_available_entriesx
  pp keys?.sort
end
show_all_matches()
Alias for: deep_show
show_help( shall_we_exit = false ) click to toggle source
#

show_help

This method is used to show the available help-options for this class.

#
# File lib/rbt/aliases/aliases.rb, line 446
def show_help(
    shall_we_exit = false
  )
  shall_we_exit = true if shall_we_exit == :then_exit
  opne 'These options exist:'
  e
  ecomment '  --n_entries # show how many cookbook entries exist'
  e
  exit if shall_we_exit
end
show_size() click to toggle source
#

show_size

#
# File lib/rbt/aliases/aliases.rb, line 260
def show_size
  opne "We have #{sfancy(n_registered_programs?.to_s)}"\
       " unique programs registered."
end
this_program?()
translate(i = program?)
Alias for: translate_alias
translate_alias(i = program?) click to toggle source
#

translate_alias

This method will try to “translate” an alias.

#
# File lib/rbt/aliases/aliases.rb, line 327
def translate_alias(i = program?)
  return dataset?[i] if is_included? # Found the result here.
  return i
end
Also aliased as: translate, value?, [], result?, result
value?(i = program_name?)
Alias for: points_at?
was_found?(i = program_name?)
Alias for: is_included?