class Cookbooks::SearchForTags

Constants

DEFAULT_SEARCH_TAG
#

DEFAULT_SEARCH_TAG

#
EXIT_ON_EMPTY_DIRECTORIES
#

EXIT_ON_EMPTY_DIRECTORIES

#
NAMESPACE
#

NAMESPACE

#
USE_THIS_DELAY
#

USE_THIS_DELAY

#

Public Class Methods

new( search_for = DEFAULT_SEARCH_TAG, run_already = true ) { || ... } click to toggle source
#

initialize

#
# File lib/cookbooks/utility_scripts/search_for_tags/initialize.rb, line 8
def initialize(
    search_for  = DEFAULT_SEARCH_TAG, # This variable is usually an Array.
    run_already = true
  )
  reset
  if search_for.is_a? Array
    if search_for.any? {|entry| entry.start_with? '--' }
      # =================================================================== #
      # Ok, this will be treated as a commandline-instruction then.
      # =================================================================== #
      _ = search_for.select {|inner_entry| inner_entry.start_with? '--' }
      menu(_)
      search_for.reject! {|inner_entry| inner_entry.start_with? '--' }
    end
  end
  set_search_for(search_for)
  if block_given?
    yielded = yield
    case yielded
    when :be_quiet
      @be_verbose = false
    end
  end
  run if run_already
end

Public Instance Methods

also_show_url?() click to toggle source
#

also_show_url?

#
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 128
def also_show_url?
  @also_show_url
end
append_to_buffer(i) click to toggle source
#

#append_to_buffer

#
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 163
def append_to_buffer(i)
  @xorg_buffer_string << i
end
array_of_programs()
Alias for: array_of_programs?
array_of_programs?() click to toggle source
#

#array_of_programs?

#
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 79
def array_of_programs?
  @array_of_programs
end
Also aliased as: array_of_programs
calculate_and_display_the_filesize_of(this_file) click to toggle source
#

#calculate_and_display_the_filesize_of

We will calculate the filesize of the given program at hand.

#
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 172
def calculate_and_display_the_filesize_of(this_file)
  this_file = this_file.dup.map {|entry|
    source_directory?+
      File.basename(entry.split(':').first).sub(/\.yml$/,'')+
      '/'
  }
  total_size = 0
  this_file.each {|entry|
    entries = Dir[entry+'*']
    if entries.size == 0
      # =================================================================== #
      # Report empty directories, but only if the entry "do_not_download"
      # was not set.
      # =================================================================== #
      program = File.basename(entry).downcase
      _ = Cookbooks::Cookbook.new(program)
      unless _.get_value_of 'do_not_download'
        if File.directory? entry # Only report it if it exists.
          opnn; e 'We found an empty directory here, at `'+sdir(entry)+'`.'
        end
      end
      exit if EXIT_ON_EMPTY_DIRECTORIES
    end
    if entries.first
      total_size += File.size(entries.first) if File.exist? entries.first
    end
  }
  total_filesize = ( total_size.to_f/1024/1024 ).round(2).to_s
  if be_verbose?
    result = N+'The total filesize is '+sfancy(total_size.to_s)+
               ' bytes. (This is '+simp(total_filesize)+' MB)'
    e result
  end
end
check_against_menu(i = search_for?)
Alias for: menu
commandline?()
Alias for: search_for?
display_every_tag( also_show_the_specific_tags = true ) click to toggle source
#

#display_every_tag

This method will show every available tag.

If the argument also_show_the_specific_tags is set to true then we will also show the specific tag.

To invoke this, do:

tags ALL
#
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 250
def display_every_tag(
    also_show_the_specific_tags = true
  )
  array = [] # This array will keep our results.
  all_programs = Cookbooks.available_programs
  all_programs.each {|program|
    opnn; e 'Checking on the program `'+sfancy(program)+'` next:'
    begin
      _ = Cookbooks::Cookbook.new(program) { :bypass_menu_check }
    rescue Exception => error
      opnn; pp error
      opnn; e program
    end
    if _
      begin
        if _.has_tags?
          e 'Yes, it has tags.'
          array << [ program, _.return_tags ] if also_show_the_specific_tags
        else # Else, it has no tags.
          # e 'No, it has no tags.'
          array << [ program, '']
        end
      rescue Exception; end
    else
      opnn; e swarn('We did not find anything about `')+simp(program)+swarn('`.')
      opnn; e swarn('This is considered a fatal error for now, thus exiting.')
      exit
    end
  }
  # ======================================================================= #
  # Now report that array:
  # ======================================================================= #
  opnn; e 'Next reporting these results:'
  array.sort_by {|key, value| value }.each {|key,value|
    value = Konsole.skyblue(value) if Object.const_defined? :Colours
    e (key+': ').ljust(left_padding?)+value
  }
end
do_not_show_the_index() click to toggle source
#

#do_not_show_the_index

#
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 95
def do_not_show_the_index
  @show_index = false
end
eparse(i) click to toggle source
#

eparse

#
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 235
def eparse(i)
  Colours.eparse(i)
end
left_padding?() click to toggle source
#

left_padding?

#
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 102
def left_padding?
  28
end
menu(i = search_for?) click to toggle source
#

menu (menu tag)

#
Also aliased as: check_against_menu
opnn() click to toggle source
#

opnn

#
Calls superclass method Cookbooks::Base#opnn
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 292
def opnn
  super(NAMESPACE)
end
reassign_this_input_to_that_registered_entry(original_input, i) click to toggle source
#

#reassign_this_input_to_that_registered_entry

#
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 478
def reassign_this_input_to_that_registered_entry(original_input, i)
  opnn; e "Reassigning input `#{simp(original_input)} to the "\
          "registered entry `#{simp(i)}`."
end
reset() click to toggle source
#

reset

#
Calls superclass method Cookbooks::Base#reset
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 66
def reset
  super()
  @xorg_buffer_string = ''.dup
  @show_index = true
  @be_verbose = true # Just to make sure that we will be verbose here.
  @also_show_url = false # if true then we will also show the URL.
  @also_open_every_entry_in_the_editor = false
  @array_of_programs = []
end
result()
Alias for: string?
result?()
Also aliased as: result
Alias for: string?
run() click to toggle source
#

run (run tag)

#
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 500
def run
  check_against_menu # Check against the menu first.
  perform_the_search # We use grep to find the tags.
end
search_for?() click to toggle source
#

search_for?

#
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 210
def search_for?
  @search_for
end
Also aliased as: commandline?, search_term?
search_term?()
Alias for: search_for?
set_search_for(i = nil) click to toggle source
#

#set_search_for

#
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 299
def set_search_for(i = nil)
  i = DEFAULT_SEARCH_TAG if i.nil?
  if i.is_a? Array and i.empty?
    i = [DEFAULT_SEARCH_TAG] # Fill up empty arrays in this case.
  end
  if i.is_a? Symbol
    i = i.to_s
  end
  if i.is_a? String
    i = i.strip # Get rid of whitespace.
    # ===================================================================== #
    # Next, sanitize some common misspellings.
    # ===================================================================== #
    if i.include? ' ' # If it includes internal ' '.
      i = i.split(' ') # Then we turn it into an Array.
    end
  end
  if i.is_a? Array # Next handle Arrays here.
    i.map! {|entry|
      if entry.include? '-' # '-' characters are useless - they are not part of a tag.
        entry = entry.dup if entry.frozen?
        entry.delete!('-')
      end
      entry
    }
    original_input = i.first
    # ===================================================================== #
    # === Sanitize operations
    #
    # Perform some sanitize-operations next, out of user-convenience.
    # ===================================================================== #
    case i.first # case tag
    when 'games'
      opnn; e 'Need to correct `'+simp(original_input)+'` to `'+
               simp('game')+'` tag.'
      i = 'game'
    when 'x11'
      i = 'xorg'
      opnn; e 'Reassigning input `'+simp(original_input)+' to `'+simp(i)+
              ' as we should have more'
      opnn; e 'tags registered that way.'
    when 'WM','windowsmanager'
      i = 'windowmanager'
      reassign_this_input_to_that_registered_entry(original_input, i)
    when 'programming_languages'
      i = 'programming_language'
      reassign_this_input_to_that_registered_entry(original_input, i)
    end
  end
  i.flatten! if i.is_a? Array
  i = [i] unless i.is_a? Array
  i.compact!
  @search_for = i # Must be an Array.
end
set_the_xorg_buffer() click to toggle source
#

#set_the_xorg_buffer

#
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 154
def set_the_xorg_buffer
  unless @xorg_buffer_string.empty?
    XorgBuffer[@xorg_buffer_string]
  end
end
show_available_tags( use_this_path = FILE_ALLOWED_TAGS ) click to toggle source
#

#show_available_tags

Simply delegate towards Cookbooks.show_available_tags.

Invocation example:

search_for_tags --show-available-tags
#
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 491
def show_available_tags(
    use_this_path = FILE_ALLOWED_TAGS
  )
  opnn; Cookbooks.show_available_tags(use_this_path, :do_not_report_the_namespace)
end
show_help() click to toggle source
#

#show_help

Invoke this method like so:

tags --help
#
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 221
def show_help # help tag
  e 'These options are available so far for class Cookbooks::SearchForTags:'
  e
  eparse '  OPEN_ALL    # open all entries in the editor'
  eparse '  WITH_URL    # also show the URL'
  eparse '  NO_INDEX    # do not show the leading numbers when listing the tags'
  eparse '  ALL         # display every tag'
  eparse '  --available # show which tags are available'
  e
end
store_results_into_file() click to toggle source
#

#store_results_into_file

#
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 142
def store_results_into_file
  this_file = store_into_this_directory?+'these_tags'
  if be_verbose?
    e # A spacer here is in order.
    opnn; e 'Now storing these results into the file `'+sfile(this_file)+'`.'
  end
  save_file(@xorg_buffer_string, this_file)
end
string()
Alias for: string?
string?() click to toggle source
#

string?

#
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 86
def string?
  @xorg_buffer_string
end
Also aliased as: string, result, result?
url?(i) click to toggle source
#

url?

Return the URL of a program. The method #perform_the_search() will display it.

#
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 112
def url?(i)
  i = i.to_s.dup
  _ = "#{cookbooks_directory?}"\
      "#{File.basename(i).split(' ').first.delete(':')}".dup
  _ << '.yml' unless _.end_with? '.yml'
  if File.exist? _ # We directly load this file.
    i = YAML.load_file(_)
    i = i[i.keys.first]['url1'].to_s
  else # File does not exist here. Should not happen.
  end
  return i
end