class BeautifulUrl::BeautifulUrl

Constants

DEFAULT_URL
#

DEFAULT_URL

#
RUN_ALREADY
#

RUN_ALREADY

#

Public Class Methods

[]( i = 'palemoon', &block ) click to toggle source
#

BeautifulUrl::BeautifulUrl['palemoon']

#
# File lib/beautiful_url/class/misc.rb, line 401
def self.[](
    i = 'palemoon', &block
  )
  new(i, &block).return_as_string
end
new( commandline_arguments = ARGV, run_already = RUN_ALREADY ) { || ... } click to toggle source
#

initialize

Usage examples:

x = BeautifulUrl::BeautifulUrl.new('palemoon', :replace_localhost)
x = BeautifulUrl::BeautifulUrl.new('palemoon' {{ replace_localhost: true }}
#
# File lib/beautiful_url/class/initialize.rb, line 54
def initialize(
    commandline_arguments = ARGV,
    run_already           = RUN_ALREADY,
    &block
  )
  reset # Must come first.
  case commandline_arguments # case tag
  # ======================================================================= #
  # === :dont_run_yet
  # ======================================================================= #
  when :dont_run_yet,
       :do_not_run_yet
    commandline_arguments = DEFAULT_URL
    run_already = false
  end
  set_commandline_arguments(
    commandline_arguments
  )
  case run_already
  # ======================================================================= #
  # === :replace_localhost
  # ======================================================================= #
  when :replace_localhost,
       :replace,
       :replace_localhost_with_data,
       :do_replace_localhost
    @replace_localhost_with_data = true # Default, as this is more important.
    run_already = RUN_ALREADY
  else
    if run_already.is_a? Hash # Must come after reset().
      # =================================================================== #
      # === :replace_localhost
      # =================================================================== #
      if run_already.has_key? :replace_localhost
        @replace_localhost_with_data = run_already[:replace_localhost]
        run_already = RUN_ALREADY # Restore the default again.
      # =================================================================== #
      # === :replace
      # =================================================================== #
      elsif run_already.has_key? :replace
        @replace_localhost_with_data = run_already[:replace]
        run_already = RUN_ALREADY # Restore the default again.
      end
    end
  end
  # ======================================================================= #
  # === Handle blocks given to us
  #
  # This has to occur before run() is called.
  # ======================================================================= #
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # === :do_not_replace_the_localhost
    # ===================================================================== #
    when :do_not_replace_the_localhost
      # In this case do nothing.
    # ===================================================================== #
    # ===:replace_localhost
    # ===================================================================== #
    when :replace_localhost
      @replace_localhost_with_data = true
    end
  end
  run if run_already
end

Public Instance Methods

[]()
Alias for: url_as_string
array()
array?()
check_input_against_menu( i = @commandline_arguments )
consider_replacing_data_with_localhost() click to toggle source
#

consider_replacing_data_with_localhost

#
# File lib/beautiful_url/class/misc.rb, line 143
def consider_replacing_data_with_localhost
  if @replace_data_with_localhost
    do_replace_data_with_localhost
  end
end
consider_replacing_localhost_with_data() click to toggle source
#

consider_replacing_localhost_with_data

#
# File lib/beautiful_url/class/misc.rb, line 152
def consider_replacing_localhost_with_data
  if @replace_localhost_with_data
    do_replace_localhost_with_data_entry
  end
end
Also aliased as: replace_localhost
data()
do_ignore_help() click to toggle source
#

do_ignore_help

#
# File lib/beautiful_url/class/misc.rb, line 355
def do_ignore_help
  @ignore_help = true
end
do_replace_data_entry_with_localhost() click to toggle source
#

do_replace_data_entry_with_localhost

#
# File lib/beautiful_url/class/misc.rb, line 170
def do_replace_data_entry_with_localhost
  @commandline_arguments.map! {|entry|
    entry = entry.dup if entry.frozen?
    if entry.include? @data_dir
      regexp_quoted = Regexp.quote(@data_dir)
      entry.sub!(regexp_quoted, HTTP_LOCALHOST_STRING)
    end
    entry
  }
end
do_replace_data_with_localhost()
do_replace_localhost()
do_replace_localhost_with_data()
do_replace_localhost_with_data_entry() click to toggle source
#

do_replace_localhost_with_data_entry

This method will replace the leading localhost-string with the corresponding data-dir value.

For example, the :

http://localhost/DATA/PC/palemoon/palemoon.cgi

Would become:

/home/x/DATA/PC/palemoon/palemoon.cgi
#
# File lib/beautiful_url/class/misc.rb, line 240
def do_replace_localhost_with_data_entry
  @commandline_arguments.map! {|entry|
    entry = entry.dup if entry.frozen?
    if entry.include? HTTP_LOCALHOST_STRING
      regexp_quoted = Regexp.quote(HTTP_LOCALHOST_STRING)
      entry.sub!(regexp_quoted, home_dir_of_user_x?)
    end
    entry
  }
end
generate_tab_completion()
generate_tab_completion_for_bash_shell() click to toggle source
#

generate_tab_completion_for_bash_shell

This entry point will generate the tab-completion for the BASH shell.

Invocation examples:

purl GENERATE
purl --generate
#
# File lib/beautiful_url/class/generate_tab_completion_for_bash_shell.rb, line 26
  def generate_tab_completion_for_bash_shell
    begin
      require 'collect_first_word_of_case_menu'
    rescue LoadError; end
    begin
      require 'opn'
    rescue LoadError; end
    opn; e 'Now generating tab completion for the bash shell.'
    _ = ''.dup # This is the string to store.
    _ << 'completion_for_purl()
{
  local cur complete_these_words
  
  COMPREPLY=() # Array variable storing the possible completions.
  cur="${COMP_WORDS[COMP_CWORD]}"
  complete_these_words="'
    beautiful_menu = ::BeautifulUrl[:beautiful_menu]
    if beautiful_menu.is_a? Array
      beautiful_menu = beautiful_menu.first
    end
    results = CollectFirstWordOfCaseMenu.new(beautiful_menu).result
    results.sort.each {|entry|
      _ << entry+"\n"
    }
    _ << ' "

  if [[ ${cur} == * ]] ; then
    COMPREPLY=( $(compgen -W "${complete_these_words}" -- ${cur}) )
    return 0
  fi
}
# Next, available auto-completion for the commands "purl" and "url".
complete -F completion_for_purl url
complete -F completion_for_purl purl
'
    store_where =
      "#{BASE_DIR}DATA/PC/OS/LINUX/SHELL/SCRIPTS/completion_for_purl.sh"
    opn; e 'We will store at `'+store_where+'`.'
    SaveFile.write_what_into(_, store_where)
  end
Also aliased as: generate_tab_completion
get_rid_of_localhost()
handle_additional_actions_after_the_input_arguments_were_already_mapped() click to toggle source
#

handle_additional_actions_after_the_input_arguments_were_already_mapped

#
# File lib/beautiful_url/class/misc.rb, line 161
def handle_additional_actions_after_the_input_arguments_were_already_mapped
  consider_replacing_localhost_with_data
  consider_replacing_data_with_localhost
end
home_dir_of_user_x?() click to toggle source
#

home_dir_of_user_x?

#
# File lib/beautiful_url/class/misc.rb, line 348
def home_dir_of_user_x?
  BASE_DIR
end
input?()
is_a_remote_file?()
Alias for: is_a_remote_url?
is_a_remote_url?() click to toggle source
#

is_a_remote_url?

This method will return true if the URL is remote, false if it is local, and nil if it was not found at all.

The variable @url_was_found will tell us whether the url was found or whether it was not.

#
# File lib/beautiful_url/class/misc.rb, line 93
def is_a_remote_url?
  if @is_registered
    _ = @commandline_arguments.all? {|entry|
      entry.include? 'http'
    }
  else
    _ = nil
  end
  _ # Our return value.
end
Also aliased as: remote?, is_a_remote_file?
is_included?()
Alias for: is_registered?
is_registered?() click to toggle source
#

is_registered?

#
# File lib/beautiful_url/class/misc.rb, line 219
def is_registered?
  @is_registered
end
location?()
Alias for: url_as_string
map_the_input_arguments_to_their_corresponding_values( i = @commandline_arguments ) click to toggle source
#

map_the_input_arguments_to_their_corresponding_values

This method will map the given input to its corresponding value, if possible.

Take note that this method will also change @is_registered if the entry was found.

#
# File lib/beautiful_url/class/misc.rb, line 32
def map_the_input_arguments_to_their_corresponding_values(
    i = @commandline_arguments
  )
  i.map! {|entry|
    if entry.is_a? Symbol
      entry = entry.to_s.dup
    end
    entry = entry.dup if entry.frozen?
    # ===================================================================== #
    # Neither ':' or ',' seem to be useful at the end, so we will chop
    # them away next (since as of October 2011). Trailing whitespace
    # will also be removed in the line afterwards.
    # ===================================================================== #
    if entry and (entry.to_s.end_with?(':') or entry.to_s.end_with?(','))
      entry.chop!
    end
    if entry and entry.is_a?(String)
      entry.rstrip!
      # =================================================================== #
      # Nor is a leading ':' useful here either.
      # =================================================================== #
      entry[0,1] = '' if entry.start_with? ':'
    end
    # ===================================================================== #
    # Handle intralink entries when they contain a '#' character.
    # ===================================================================== #
    if entry and entry.is_a?(String) and entry.include?('#')
      splitted = entry.split('#')
      set_intralink(splitted.last)
      entry = splitted.first
    end
    old_value = entry.to_s.dup # Use a reference copy here.
    new_value = ::BeautifulUrl.menu(entry)
    new_value.flatten! if new_value.is_a? Array
    if new_value == old_value
      # =================================================================== #
      # In this case we did not find anything, so we don't do anything.
      # =================================================================== #
    else
      @is_registered = true
      entry = new_value
    end
    if @intralink and !@intralink.empty?
      entry = entry.dup if entry.frozen?
      entry << @intralink # Append in this case.
    end
    entry
  }
  i.flatten!
end
menu( i = @commandline_arguments ) click to toggle source
#

menu (menu tag)

#
remote?()
Alias for: is_a_remote_url?
replace_localhost()
replace_localhost_with_data()
replace_localhost_with_data?() click to toggle source
#

replace_localhost_with_data?

#
# File lib/beautiful_url/class/misc.rb, line 268
def replace_localhost_with_data?
  @replace_localhost_with_data
end
Also aliased as: replace_localhost_with_data
reset() click to toggle source
#

reset (reset tag)

#
# File lib/beautiful_url/class/reset.rb, line 14
def reset
  set_intralink
  set_data_dir(:default)
  # ======================================================================= #
  # === @commandline_arguments
  # ======================================================================= #
  @commandline_arguments = []
  # ======================================================================= #
  # === @is_registered
  #
  # By default the given input is NOT registered. A method can change
  # this value at a later time. (In the past this variable was called
  # @url_was_found, but during the rewrite in early 2020 it was
  # renamed).
  # ======================================================================= #
  @is_registered = false # Will become true if the URL was found.
  # ======================================================================= #
  # === @replace_localhost_with_data
  #
  # This variable must be false by default. If true then we will replace
  # the localhost string with the DATA/ string.
  # ======================================================================= #
  @replace_localhost_with_data = false
  # ======================================================================= #
  # === @replace_data_with_localhost
  # ======================================================================= #
  @replace_data_with_localhost = false
  # ======================================================================= #
  # === @ignore_help
  #
  # This variable can be used to specifically NOT make use of --help,
  # that is to ignore this case even if the user specified it.
  # ======================================================================= #
  @ignore_help = false
end
result()
Alias for: url_as_string
result?()
Alias for: url_as_string
results?() click to toggle source
#

results?

#
# File lib/beautiful_url/class/misc.rb, line 334
def results?
  @commandline_arguments
end
return_as_string()
Alias for: url_as_string
return_corresponding_entries() click to toggle source
#

return_corresponding_entries

#
# File lib/beautiful_url/class/misc.rb, line 317
def return_corresponding_entries
  @commandline_arguments
end
Also aliased as: input?, data, array, array?
return_corresponding_entry() click to toggle source
#

return_corresponding_entry

#
# File lib/beautiful_url/class/misc.rb, line 327
def return_corresponding_entry
  @commandline_arguments.first
end
Also aliased as: url?
run() click to toggle source
#

run

#
# File lib/beautiful_url/class/run.rb, line 14
def run
  menu
  map_the_input_arguments_to_their_corresponding_values
  handle_additional_actions_after_the_input_arguments_were_already_mapped
end
sanitize_input( i = @commandline_arguments )
search_for_this_url(i) click to toggle source
#

search_for_this_url

This will return a string.

#
# File lib/beautiful_url/class/misc.rb, line 133
def search_for_this_url(i)
  set_commandline_arguments(i)
  map_the_input_arguments_to_their_corresponding_values
  handle_additional_actions_after_the_input_arguments_were_already_mapped
  return string?
end
set_commandline_arguments(i = :default) click to toggle source
#

set_commandline_arguments

#
# File lib/beautiful_url/class/misc.rb, line 256
def set_commandline_arguments(i = :default)
  case i
  when nil
    i = DEFAULT_URL
  end
  i = [i].flatten.compact
  @commandline_arguments = i
end
set_data_dir( i = :default ) click to toggle source
#

set_data_dir

We need this method so that the user can define another data-dir that is to be used.

#
# File lib/beautiful_url/class/misc.rb, line 300
def set_data_dir(
    i = :default
  )
  case i
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default,
       nil
    i = DATA_DIR
  end
  @data_dir = i
end
set_replace_localhost( i = true )
set_shall_we_replace_localhost( i = true ) click to toggle source
#

set_shall_we_replace_localhost

This method simply sets @replace_localhost_with_data to the passed value, which is true by default.

If true, we will replace the “localhost” string with the DATA constant.

Parameters can be like this:

:replace => true     # Yes, replace localhost with data.
:replace => false    # No, do not replace localhost with data.
:replace => :reverse # Replace data with localhost, which is the reverse.
#
# File lib/beautiful_url/class/misc.rb, line 121
def set_shall_we_replace_localhost(
    i = true
  )
  @replace_localhost_with_data = i
end
shall_we_replace_localhost=( i = true )
show_help( shall_we_exit = :then_exit ) click to toggle source
#

show_help

#
# File lib/beautiful_url/class/misc.rb, line 362
def show_help(
    shall_we_exit = :then_exit
  )
  unless @ignore_help
    opn
    e 'To issue the various instructions, use AUTOGENERATED or GENERATED.'
    e
    e 'Alternative, it works as a downcased variant as well, with -- as in:'
    e
    e '  --autogenerate'
    e '  --generate'
    e
    exit if shall_we_exit == :then_exit
  end
end
show_result() click to toggle source
#

show_result

#
# File lib/beautiful_url/class/misc.rb, line 341
def show_result
  e return_corresponding_entry
end
string()
Alias for: url_as_string
string?()
Alias for: url_as_string
url?()
url_as_string() click to toggle source
#

url_as_string

Return the @input in string variant, always. This can be used as content that can be displayed in other programs.

Take note that in the past result? returned an Array, from 02.08.2015 up until 04.01.2020. Past that point it will return a String instead.

#
# File lib/beautiful_url/class/misc.rb, line 387
def url_as_string
  return_corresponding_entry.to_s
end
Also aliased as: url?, location?, string, string?, result?, result, return_as_string, []
url_was_found()
Alias for: is_registered?
url_was_found?()
Alias for: is_registered?