class RBT::GatherInformation

Constants

ARRAY_ALLOWED_TASKS
#

ARRAY_ALLOWED_TASKS

#
B
BR
CB
CDIV
CP
DEFAULT_MODE_TO_USE
#

DEFAULT_MODE_TO_USE

#
DIV
EXIT_ON_FAULTY_COOKBOOK_DISCOVERED
#

EXIT_ON_FAULTY_COOKBOOK_DISCOVERED

#
INFO_DIR
#

INFO_DIR

#
NAMESPACE
#

NAMESPACE

#
P

Public Class Methods

new( mode_to_use = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/utility_scripts/gather_information.rb, line 77
def initialize(
    mode_to_use = nil,
    run_already = true
  )
  reset
  set_mode_to_use(
    mode_to_use
  )
  run if run_already
end

Public Instance Methods

feedback_information( on_these_applications = @mode_to_use ) click to toggle source
#

feedback_information

No need for more than one “when” clauses / entry, because this method will be invoked only after it was sanitized - see above.

#
# File lib/rbt/utility_scripts/gather_information.rb, line 126
def feedback_information(
    on_these_applications = @mode_to_use
  )
  # ======================================================================= #
  # The argument on_these_applications could be :all.
  # ======================================================================= #
  if on_these_applications.is_a? Array
    on_these_applications = on_these_applications.join(', ')
  end
  # ======================================================================= #
  # === Check whether we have included this task
  # ======================================================================= #
  unless ARRAY_ALLOWED_TASKS.include? on_these_applications
    opnn; e 'Not a registered task: '+simp(on_these_applications.to_s)
    opnn; e
    opnn; e 'Please choose among these registered entries:'
    opnn; e
    e
    e ARRAY_ALLOWED_TASKS.map {|entry| ' - '+entry.to_s }
    e
    exit
  end
  # ======================================================================= #
  # === Handle help instructions issued
  # ======================================================================= #
  unless on_these_applications == :HELP
    opnn; e simp('Reporting info on `')+sfancy(on_these_applications.to_s)+
            simp('` next.')
  end
  case on_these_applications # case tag
  # ======================================================================= #
  # === ginformation html
  # ======================================================================= #
  when :html, :htm, :ht, :h
    # :html will generate HTML links of all programs
    generate_html
  # ======================================================================= #
  # === ginformation --help
  # ======================================================================= #
  when :HELP # When the user asked for help.
    show_usage
  # ======================================================================= #
  # === ginformation --all
  # ======================================================================= #
  when :all # :all will output all URL pages.
    feedback_information :html
    feedback_information :video
    feedback_information :audio
    feedback_information :games
    feedback_information :html_project
  when :lfs, :lfs_page, :html_project, :html_pages
    generate_html_project
  when :video, :vid
    @_.each { |program|
      seek_program(program)
      feedback_url if @data['tags'].to_s.include? 'vid'
    }
  when :audio, :aud
    @_.each { |program|
      seek_program(program)
      feedback_url if @data['tags'].to_s.include? 'aud'
    }
  # ======================================================================= #
  # Next, we try to find all games. This can be done if tags
  # includes games.
  # ======================================================================= #
  when :games
    @_.each { |game|
      seek_program(game)
      feedback_url if @data['tags'].include? 'game'
    }
  else
  end
end
feedback_url() click to toggle source
#

feedback_url

#
# File lib/rbt/utility_scripts/gather_information.rb, line 114
def feedback_url # This gives us the url.
  unless @data['url1'].to_s.empty?
    e '  '+@data['short_name'].to_s+': '+sfancy(@data['url1'])
  end
end
generate_html( i = @html_file ) click to toggle source
#

generate_html (html tag)

This method will generate a HTML file.

To generate the html section, simply do:

rinfo html
#
# File lib/rbt/utility_scripts/gather_information.rb, line 259
def generate_html(
    i = @html_file
  )
  opnn; e 'Generating a HTML file next.'
  opnn; e "Will store into `#{sfile(i)}`."
  remove(i) if File.exist? i # Let's remove the old file if it exists.
  # ======================================================================= #
  # Build up the HTML Header. We will store this eventually.
  # ======================================================================= #
  string_to_store =
    '<html><head><title>Information about installed programs</title></head><body>'.dup
  @_.each { |program|
    seek_program(program)
    name = @data['program_name']+N
    opnn; e "  #{name.chomp}" # Output on the console to the user here.
    string_to_store << 
      '<div style="margin-top:5px;border: 3px dotted darkgreen;padding:0.40em">'+N
    string_to_store << '<b style="font-size:1.5em;color:darkblue"> Name: '+name+CB+BR
    description = @data['description']
    unless description.empty?
      string_to_store << "#{BR}<b style=\"background-color:violet;font-size:1.45em\"> "\
      "Description: </b>#{BR}"\
      "<b style=\"font-size:1.0em; padding-left:1.5em; padding-right:1.5em; margin-left:3em\">"\
      "#{description}#{N}</b>"
    end
    # ===================================================================== #
    # Add URL1 next.
    # ===================================================================== #
    string_to_store << BR+'<b style="padding-left:3em;font-size:0.95em"> 
        URL1:</b> <a href="'+@data['url1'].to_s+'">'+
        @data['url1'].to_s+'</a><br>'+BR+N
    second_url = @data['url2']
    if second_url
      string_to_store << '<b style="padding-left:3em;font-size:0.95em"> 
        URL2:</b> <a href="'+second_url+'">'+second_url+'</a><br>'+BR+N
    end
    string_to_store << '</div>'+N+'<hr>'
  }
  string_to_store << '</body></html>'
  save_file(string_to_store, i) # Finally we save the string.
  opnn; e 'We did find `'+simp(@available_programs.size.to_s)+'` registered programs.'
  opnn; e 'Finished! Stored into `'+sfile(i)+'`.'
end
generate_html_project() click to toggle source
#

generate_html_project (html tag)

#
# File lib/rbt/utility_scripts/gather_information.rb, line 214
def generate_html_project # This will generate a big html project, like LFS.
  @_.each_with_index { |program, index|
    # next if index > 30 # This line can be re-enabled if you want to debug.
    seek_program(program)
    name = @data['program_name']
    e '  '+name.chomp # Output on the console to the user here.
    where = INFO_DIR+program+'.html'
    description = @data['description']
    dependencies = @data['required_deps_on']
    @array_all_html_pages << [
      @data['short_name'], name, where, description, dependencies
    ]
  }
  @array_all_html_pages.each_with_index {|entry, index|
    previous_url = '' # The URL before.
    next_url     = '' # The URL after
    previous_url = @array_all_html_pages[index-1][2] if @array_all_html_pages[index-1]
    next_url     = @array_all_html_pages[index+1][2] if @array_all_html_pages[index+1]
    main_url     = entry[2].to_s # Itself.
    description  = entry[3].to_s
    dependencies = entry[4].to_s
    _ = ''.dup
    _ << '<html><title>'+entry.first.to_s+'</title>'+N
    _ << '<body style="padding:5px; font-size:1.2em">'+N
    _ << '<h1 style="text-align: center">'+entry[0]+'</h1>'+N
    _ << B+'Introduction to '+entry[0]+CB+BR
    _ << entry[0]+BR+B+' Dependencies'+CB+BR+B+'Required'+CB+BR+dependencies+BR
    #_ << DIV+'Description:'+BR+P+description+CP+CDIV
    _ << HtmlTags.div { 'Description:'+BR+P+description+CP }
    _ << DIV+'<a href="'+previous_url+'">'+File.basename(previous_url)+'</a>'+BR
    _ << '<a href="'+next_url+'">'+File.basename(next_url)+'</a>'+BR+CDIV
    _ << '</body></html>'+N
    opnn; e 'Storing into '+sfile(main_url)+'.'
    save_file(_, main_url)
  }
end
reset() click to toggle source
#

reset

#
Calls superclass method RBT::Base#reset
# File lib/rbt/utility_scripts/gather_information.rb, line 91
def reset
  super()
  @namespace = NAMESPACE
  @cookbook_dataset = RBT::Cookbooks::Cookbook.new { :bypass_menu }
  @_ = @available_programs = return_available_programs
  # @html_file = '/Depot/Temp/Test.html'
  @html_file = INFO_DIR+'ApplicationsFeedback.html'
  @array_all_html_pages = [] # All html pages are stored here.
end
run() click to toggle source
#

run

#
# File lib/rbt/utility_scripts/gather_information.rb, line 331
def run # run tag
  feedback_information
end
seek_program(i) click to toggle source
#

seek_program

This method can be used to seek to the program at hand. Since as of December 2017, we will first try to load an expanded dataset.

#
# File lib/rbt/utility_scripts/gather_information.rb, line 309
def seek_program(i)
  begin # Tap into class Cookbook next.
    possible_target_at_expanded_cookbooks = "#{RBT.rbt_log_directory?}expanded_cookbooks/#{i.delete('-_')}"
    if File.exist? possible_target_at_expanded_cookbooks
      @data = YAML.load_file(possible_target_at_expanded_cookbooks)
    else
      @cookbook_dataset = RBT::Cookbooks::Cookbook.new(i) { :bypass_menu_check } # Find again here.
      @data = @cookbook_dataset.return_dataset
    end
  rescue ArgumentError => error
    opnn; e 'An error happened, probably in the yaml file.'
    opnn; e 'The error is:'
    pp error
    pp error.class
    opnn; e 'The faulty program was: '+simp(i)
    exit if EXIT_ON_FAULTY_COOKBOOK_DISCOVERED
  end
end
set_mode_to_use(i) click to toggle source
#

set_mode_to_use

#
# File lib/rbt/utility_scripts/gather_information.rb, line 104
def set_mode_to_use(i)
  i = DEFAULT_MODE_TO_USE if i.nil?
  i = i.first if i.is_a? Array # For now, get only the first argument.
  i = i.to_sym if i.is_a? String
  @mode_to_use = i
end
show_usage() click to toggle source
#

show_usage

#
# File lib/rbt/utility_scripts/gather_information.rb, line 204
def show_usage
  opnn; e 'This umbrella project allows you to feedback all sorts of'
  opnn; e 'useful information. You can even generate chained HTML'
  opnn; e 'pages, such as in use by the LFS project.'; print '  '
  opnn; pp ARRAY_ALLOWED_TASKS
end