class RBT::Cookbooks::AllUrls

Constants

NAMESPACE
#

NAMESPACE

#

Public Class Methods

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

initialize

#
# File lib/rbt/utility_scripts/all_urls.rb, line 39
def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  if commandline_arguments
    set_commandline_arguments(commandline_arguments)
  end
  run if run_already
end

Public Instance Methods

check_for_commandline_arguments() click to toggle source
#

check_for_commandline_arguments

We will work on a String - no need to care for Symbols here.

#
# File lib/rbt/utility_scripts/all_urls.rb, line 105
def check_for_commandline_arguments
  case commandline?.to_s # case tag
  # ======================================================================= #
  # === all_urls --no-opn
  # ======================================================================= #
  when /-?-?no(_|-)?opn/,'disable_opn'
    no_opn
  # ======================================================================= #
  # === all_urls --help
  # ======================================================================= #
  when 'HELP',/^-?-?help/
    show_help
  # when 'MISSING','--missing','missing'
  #   @show_only_missing_programs = true
  end
end
commandline?() click to toggle source
#

commandline?

#
# File lib/rbt/utility_scripts/all_urls.rb, line 88
def commandline?
  @commandline_arguments
end
data?() click to toggle source
#

data?

#
# File lib/rbt/utility_scripts/all_urls.rb, line 135
def data?
  @array
end
Also aliased as: result?
display_start_message_to_the_user() click to toggle source
#

display_start_message_to_the_user

#
# File lib/rbt/utility_scripts/all_urls.rb, line 95
def display_start_message_to_the_user
  opnn; e 'We will gather all URLs next - this may take a '\
          'short while. Please remain patient.'
end
report_result( i = data? ) click to toggle source
#

report_result

Here we can report the result, which is usually what we stored in our main array called @array.

#
# File lib/rbt/utility_scripts/all_urls.rb, line 164
def report_result(
    i = data?
  )
  index_counter = 0
  buffer_string = ''.dup # This will become the Xorg buffer-string.
  pad_right = ' ' * 41
  # ======================================================================= #
  # Next we iterate over our result.
  # ======================================================================= #
  i.each {|name_of_the_program, remote_url1, remote_url2|
    string_to_display = ''.dup
    name_of_the_program = name_of_the_program.strip
    increase_index_counter = true
    remote_url1 = remote_url1.to_s.strip
    index_counter += 1 if increase_index_counter
    colourized_counter = index_counter.to_s.rjust(7)
    colourized_counter = slateblue(index_counter)
    string_to_display << ('('+colourized_counter+') ').rjust(15)
    # ===================================================================== #
    # Build the return String next.
    # ===================================================================== #
    remote_url1 = colourize_this_link(remote_url1)
    string_to_display = ''.dup
    string_to_display << name_of_the_program.ljust(30)+' -> '
    string_to_display << remote_url1.strip.ljust(40)+N
    buffer_string << string_to_display
    if show_url2?
      remote_url2 = pad_right+remote_url2.strip
      buffer_string << string_to_display
      string_to_display << colourize_this_link(
        remote_url2
      )+N
      buffer_string << N
    end
    buffer_string << string_to_display
    e string_to_display
  }
  # ======================================================================= #
  # Also assign this to the xorg buffer.
  # ======================================================================= #
  set_the_xorg_buffer_next(buffer_string)
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/utility_scripts/all_urls.rb, line 61
def reset
  super()
  @xorg_buffer = nil
  @array = []
  @use_opn = true # Whether to call opnn() or whether we don't.
  @namespace = NAMESPACE
  @also_show_url2 = true # <- Whether to try to show url2, too.
  set_commandline_arguments(nil) # Initialize @commandline_arguments here.
end
result?()
Alias for: data?
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/utility_scripts/all_urls.rb, line 224
def run
  check_for_commandline_arguments
  display_start_message_to_the_user
  all_programs = available_programs?
  all_programs.each {|program|
    result = RBT.find_url_for(program) # bl $COOKBOOKS/module_methods/module_methods.rb
    url1 = result.first.to_s.strip
    url2 = result.last.to_s.strip
    @array << [program, url1, url2]
  }
  report_result
  save_result
end
save_result() click to toggle source
#

save_result

#
# File lib/rbt/utility_scripts/all_urls.rb, line 149
def save_result
  if @xorg_buffer
    what = @xorg_buffer
    into = "#{temp_dir?}All_Urls.md"
    opnn; e "We will store this result in the file `#{sfile(into)}`."
    write_what_into(what, into)
  end
end
set_commandline_arguments(i = ARGV) click to toggle source
#

set_commandline_arguments

#
# File lib/rbt/utility_scripts/all_urls.rb, line 53
def set_commandline_arguments(i = ARGV)
  i = i.join(' ').strip if i.is_a? Array
  @commandline_arguments = i # Will be kept as String.
end
set_the_xorg_buffer_next(i = '') click to toggle source
#

set_the_xorg_buffer_next

#
# File lib/rbt/utility_scripts/all_urls.rb, line 210
def set_the_xorg_buffer_next(i = '')
  if i.empty?
    opnn; e 'We can not set the xorg buffer as the input is empty.'
  else
    e; opnn; e 'We will set the xorgbuffer next with the above '\
              'programs as our result.'
    @xorg_buffer = i
    set_xorg_buffer(@xorg_buffer)
  end
end
show_help() click to toggle source
#

show_help (help tag)

#
# File lib/rbt/utility_scripts/all_urls.rb, line 125
def show_help
  e
  e 'Use '+simp('--missing')+' if you wish to display only the programs'
  e 'without an URL entry.'
  e
end
show_url2?() click to toggle source
#

show_url2?

#
# File lib/rbt/utility_scripts/all_urls.rb, line 74
def show_url2?
  @also_show_url2
end
use_opn?() click to toggle source
#

use_opn?

#
# File lib/rbt/utility_scripts/all_urls.rb, line 81
def use_opn?
  @use_opn
end