class RBT::Cookbooks::SearchForTags

Constants

DEFAULT_SEARCH_TAG
#

DEFAULT_SEARCH_TAG

#
EXIT_ON_EMPTY_DIRECTORIES
#

EXIT_ON_EMPTY_DIRECTORIES

Whether to exit on empty directories or whether not.

#
USE_THIS_DELAY
#

USE_THIS_DELAY

If we open in the editor, we will use this delay.

#
USE_XORG_BUFFER
#

USE_XORG_BUFFER

This constant can be set to automatically set the xorg buffer.

This may be useful sometimes - but it can also be annoying, which is why it is a constant that can be toggled by the user.

#

Public Class Methods

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

initialize

#
# File lib/rbt/cookbooks/search_for_tags/search_for_tags.rb, line 87
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)
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # === :be_quiet
    # ===================================================================== #
    when :be_quiet
      set_be_quiet
    end
  end
  run if run_already
end

Public Instance Methods

also_show_url?() click to toggle source
#

also_show_url?

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

append_to_buffer

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

array_of_programs?

#
# File lib/rbt/cookbooks/search_for_tags/search_for_tags.rb, line 329
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/rbt/cookbooks/search_for_tags/search_for_tags.rb, line 252
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
      _ = action(:SanitizeCookbook, program) { :fast }
      unless _.do_not_download?
        if File.directory? entry # Only report it if it exists.
          opne '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 = "#{rev}#{N}The total filesize is #{sfancy(total_size.to_s)} "\
             "#{rev}bytes. (This is #{simp(total_filesize)}#{rev} 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/rbt/cookbooks/search_for_tags/search_for_tags.rb, line 412
def display_every_tag(
    also_show_the_specific_tags = true
  )
  array = [] # This array will keep our results.
  all_programs = available_programs?
  all_programs.each {|program|
    opne "#{rev}Checking on the program `#{sfancy(program)}#{rev}` next:"
    begin
      _ = action(:SanitizeCookbook, program) { :fast }
    rescue Exception => error
      opnn; pp error
      opne 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
      owarn "We did not find anything about `#{simp(program)}#{swarn('`.')}"
      owarn 'This is considered a fatal error for now, thus exiting.'
      exit
    end
  }
  # ======================================================================= #
  # Now report that array:
  # ======================================================================= #
  opne "#{rev}Next reporting these results:"
  array.sort_by {|key, value| value }.each {|key,value|
    value = 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/rbt/cookbooks/search_for_tags/search_for_tags.rb, line 345
def do_not_show_the_index
  @show_index = false
end
left_padding?() click to toggle source
#

left_padding?

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

menu (menu tag)

#
Also aliased as: check_against_menu
reassign_this_input_to_that_registered_entry(original_input, i) click to toggle source
#

reassign_this_input_to_that_registered_entry

#
# File lib/rbt/cookbooks/search_for_tags/search_for_tags.rb, line 677
def reassign_this_input_to_that_registered_entry(original_input, i)
  opne "#{rev}Reassigning input `#{simp(original_input)} #{rev}to "\
       "the registered entry `#{simp(i)}#{rev}`."
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::LeanPrototype#reset
# File lib/rbt/cookbooks/search_for_tags/search_for_tags.rb, line 122
def reset
  super()
  infer_the_namespace
  try_to_require_the_xorg_buffer
  # ======================================================================= #
  # === @use_xorg_buffer
  # ======================================================================= #
  @use_xorg_buffer = USE_XORG_BUFFER
  # ======================================================================= #
  # === @xorg_buffer_string
  # ======================================================================= #
  @xorg_buffer_string = ''.dup
  # ======================================================================= #
  # === @show_index
  # ======================================================================= #
  @show_index = true
  # ======================================================================= #
  # === :be_verbose
  # ======================================================================= #
  set_be_verbose # Just to make sure that we will be verbose here.
  # ======================================================================= #
  # === @also_show_url
  #
  # If true then we will also show the URL.
  # ======================================================================= #
  @also_show_url = false
  # ======================================================================= #
  # === @also_open_every_entry_in_the_editor
  # ======================================================================= #
  @also_open_every_entry_in_the_editor = false
  # ======================================================================= #
  # === @array_of_programs
  # ======================================================================= #
  @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/rbt/cookbooks/search_for_tags/search_for_tags.rb, line 701
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/rbt/cookbooks/search_for_tags/search_for_tags.rb, line 394
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/rbt/cookbooks/search_for_tags/search_for_tags.rb, line 454
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.compact! # Remove nil entries as these can arise when we passed input through menu().
    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.
    #
    # Input such as 'kde_apps' will become substituted towards the
    # longer variant called 'kde_application'.
    # ===================================================================== #
    case i.first # case tag
    # ===================================================================== #
    # === kde_application
    # ===================================================================== #
    when 'kdeapp',
         'kdeapplicates',
         'kdeapplications',
         'kde_applications',
         'kde_apps',
         /kdeapps/i
      i = 'kde_application'
      reassign_this_input_to_that_registered_entry(original_input, i)
    # ===================================================================== #
    # === xorg
    # ===================================================================== #
    when 'x11'
      i = 'xorg'
      opne 'Reassigning input `'+simp(original_input)+rev+
           " to `#{simp(i)} as we should have more"
      opne 'tags registered that way.'
    # ===================================================================== #
    # === game
    # ===================================================================== #
    when 'games'
      opne 'Need to correct `'+simp(original_input)+'` to `'+
            simp('game')+'` tag.'
      i = 'game'
    # ===================================================================== #
    # === windowmanager
    # ===================================================================== #
    when 'WM',
         'wm',
         'windowsmanager'
      i = 'windowmanager'
      reassign_this_input_to_that_registered_entry(original_input, i)
    # ===================================================================== #
    # === programming_language
    # ===================================================================== #
    when 'programming_languages'
      i = 'programming_language'
      reassign_this_input_to_that_registered_entry(original_input, i)
    # ===================================================================== #
    # === scanning
    # ===================================================================== #
    when 'scanning'
      i = 'scanner'
    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( i = @xorg_buffer_string ) click to toggle source
#

set_the_xorg_buffer

#
# File lib/rbt/cookbooks/search_for_tags/search_for_tags.rb, line 309
def set_the_xorg_buffer(
    i = @xorg_buffer_string
  )
  if use_xorg_buffer?
    unless i.empty?
      set_xorg_buffer(i)
    end
  end
end
show_available_tags( use_this_path = RBT.file_allowed_tags ) click to toggle source
#

show_available_tags

Simply delegate towards Cookbooks.show_available_tags.

Invocation example:

searchfortags --show-available-tags
#
# File lib/rbt/cookbooks/search_for_tags/search_for_tags.rb, line 692
def show_available_tags(
    use_this_path = RBT.file_allowed_tags
  )
  opnn; RBT.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/rbt/cookbooks/search_for_tags/search_for_tags.rb, line 166
def show_help # help tag
  e 'The following options are available for class '+
    steelblue('RBT::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'
  eparse '  --open-in-editor # batch-open all files with that '\
         'tag in the main editor'
  e
end
store_results_into_file() click to toggle source
#

store_results_into_file

#
# File lib/rbt/cookbooks/search_for_tags/search_for_tags.rb, line 373
def store_results_into_file
  this_file = store_into_this_directory?+'these_tags'
  if be_verbose?
    e # A spacer here is in order.
    opne "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/rbt/cookbooks/search_for_tags/search_for_tags.rb, line 336
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/rbt/cookbooks/search_for_tags/search_for_tags.rb, line 293
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
use_xorg_buffer?() click to toggle source
#

use_xorg_buffer?

#
# File lib/rbt/cookbooks/search_for_tags/search_for_tags.rb, line 322
def use_xorg_buffer?
  @use_xorg_buffer
end