class Cookbooks::AllUrls

Constants

NAMESPACE
#

NAMESPACE

#

Public Class Methods

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

initialize

#
# File lib/cookbooks/utility_scripts/all_urls.rb, line 38
def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  set_commandline_arguments(commandline_arguments) if commandline_arguments
  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/cookbooks/utility_scripts/all_urls.rb, line 107
def check_for_commandline_arguments
  case commandline?.to_s # case tag
  when 'no_opn','disable_opn'
    no_opn
  when 'HELP','--help','help'
    show_help
  # when 'MISSING','--missing','missing'
  #   @show_only_missing_programs = true
  end
end
commandline?() click to toggle source
#

commandline?

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

data?

#
# File lib/cookbooks/utility_scripts/all_urls.rb, line 129
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/cookbooks/utility_scripts/all_urls.rb, line 83
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
no_opn() click to toggle source
#

#no_opn

#
# File lib/cookbooks/utility_scripts/all_urls.rb, line 91
def no_opn
  @use_opn = false
end
opnn() click to toggle source
#

opnn

#
Calls superclass method Cookbooks::Base#opnn
# File lib/cookbooks/utility_scripts/all_urls.rb, line 98
def opnn
  super(NAMESPACE) if use_opn?
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/cookbooks/utility_scripts/all_urls.rb, line 139
def report_result(i = data?)
  index_counter = 0
  buffer_string = ''.dup # This will become the Xorg buffer-string.
  # ======================================================================= #
  # Next we iterate over our result.
  # ======================================================================= #
  i.each {|name_of_the_program, remote_url|
    string_to_display = ''.dup
    name_of_the_program = name_of_the_program.strip
    increase_index_counter = true
    remote_url = remote_url.to_s.strip
    index_counter += 1 if increase_index_counter
    colourized_counter = index_counter.to_s.rjust(7)
    if Object.const_defined? :Konsole # Use prettier colours in this case.
      colourized_counter = Konsole.slateblue(index_counter) 
    else
      colourized_counter = sfancy(index_counter)
    end
    # ===================================================================== #
    # Build the return String next.
    # ===================================================================== #
    if Object.const_defined? :Colours
      remote_url = Colours::Konsole.palevioletred(remote_url)
    end
    string_to_display = ''
    # string_to_display = ' ' if i.size > 9
    # ===================================================================== #
    # Format the index counter a little
    # Hmm does not work very well.
    # ===================================================================== #
    # string_to_display << (' ' * index_counter.size).rjust(5)
    string_to_display << ('('+colourized_counter+') ').rjust(15)+
                          name_of_the_program.ljust(30)+' -> '
    string_to_display << remote_url.strip.ljust(40)+N
    buffer_string << string_to_display
    # opnn; e 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 Cookbooks::Base#reset
# File lib/cookbooks/utility_scripts/all_urls.rb, line 58
def reset
  super()
  @xorg_buffer = nil
  @array = []
  @use_opn = true # Whether to call opnn() or whether we don't.
  set_commandline_arguments(nil) # Initialize @commandline_arguments here.
end
result?()
Alias for: data?
run() click to toggle source
#

run (run tag)

#
# File lib/cookbooks/utility_scripts/all_urls.rb, line 212
def run
  check_for_commandline_arguments
  display_start_message_to_the_user
  all_programs = Cookbooks.available_programs?
  all_programs.each {|program|
    url = Cookbooks.find_url_for(program) # bl $COOKBOOKS/module_methods/module_methods.rb
    @array << [program, url.strip]
  }
  report_result
  save_result
end
save_result() click to toggle source
#

#save_result

#
# File lib/cookbooks/utility_scripts/all_urls.rb, line 200
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/cookbooks/utility_scripts/all_urls.rb, line 50
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/cookbooks/utility_scripts/all_urls.rb, line 186
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/cookbooks/utility_scripts/all_urls.rb, line 121
def show_help
  e 'Use '+simp('--missing')+' if you wish to display only the programs'
  e 'without an URL entry.'
end
use_opn?() click to toggle source
#

use_opn?

#
# File lib/cookbooks/utility_scripts/all_urls.rb, line 69
def use_opn?
  @use_opn
end