class RBT::Action::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

#
P

Public Class Methods

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

RBT::Action::GatherInformation[]

#
# File lib/rbt/actions/individual_actions/information/gather_information.rb, line 369
def self.[](i = ARGV)
  new(i)
end
new( mode_to_use = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/actions/individual_actions/information/gather_information.rb, line 85
def initialize(
    mode_to_use = nil, # We specifically avoid using ARGV here.
    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/actions/individual_actions/information/gather_information.rb, line 148
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
    opne "Not a registered task: #{simp(on_these_applications.to_s)}"
    opne
    opne 'Please choose among these registered entries:'
    opne
    e
    e ARRAY_ALLOWED_TASKS.map {|entry| ' - '+entry.to_s }
    e
    exit
  end
  # ======================================================================= #
  # === Handle help instructions issued
  # ======================================================================= #
  unless on_these_applications == :HELP
    opne 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
  # ======================================================================= #
  # === :lfs
  # ======================================================================= #
  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'
    }
  # === :audio
  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( url1 = @data['url1'] ) click to toggle source
#

feedback_url

This gives us the url.

#
# File lib/rbt/actions/individual_actions/information/gather_information.rb, line 134
def feedback_url(
    url1 = @data['url1']
  )
  unless url1.to_s.empty?
    e '  '+@data['short_name'].to_s+": #{sfancy(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/actions/individual_actions/information/gather_information.rb, line 289
def generate_html(
    i = @html_file
  )
  opne 'Generating a HTML file next.'
  opne "#{rev}Will store into `#{sfile(i)}#{rev}`."
  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
    opne "  #{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.
  opne 'We did find `'+simp(@available_programs.size.to_s)+
       '` registered programs.'
  opne "#{rev}Finished! Stored into `#{sfile(i)}`."
end
generate_html_project() click to toggle source
#

generate_html_project (html tag)

#
# File lib/rbt/actions/individual_actions/information/gather_information.rb, line 244
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
    opne 'Storing into '+sfile(main_url)+'.'
    save_file(_, main_url)
  }
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Action#reset
# File lib/rbt/actions/individual_actions/information/gather_information.rb, line 97
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @cookbook_dataset
  # ======================================================================= #
  @cookbook_dataset = action(:SanitizeCookbook, :do_not_run_yet) { :fast }
  # ======================================================================= #
  # == @_
  # ======================================================================= #
  @_ = @available_programs = return_available_programs
  # ======================================================================= #
  # === @html_file
  # @html_file = '/Depot/Temp/Test.html'
  # ======================================================================= #
  @html_file = INFO_DIR+'ApplicationsFeedback.html'
  # ======================================================================= #
  # === @array_all_html_pages
  # ======================================================================= #
  @array_all_html_pages = [] # All html pages are stored here.
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/actions/individual_actions/information/gather_information.rb, line 362
def run
  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/actions/individual_actions/information/gather_information.rb, line 340
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 = action(:SanitizeCookbook, i) { :fast } # Find again here.
      @data = @cookbook_dataset.return_dataset
    end
  rescue ArgumentError => error
    opne 'An error happened, probably in the yaml file.'
    opne 'The error is:'
    pp error
    pp error.class
    opne '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/actions/individual_actions/information/gather_information.rb, line 122
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/actions/individual_actions/information/gather_information.rb, line 234
def show_usage
  opne 'This umbrella project allows you to feedback all sorts of'
  opne 'useful information. You can even generate chained HTML'
  opne 'pages, such as in use by the LFS project.'; print '  '
  opnn; pp ARRAY_ALLOWED_TASKS
end