class RBT::Cookbooks::Url

Constants

NAMESPACE
#

NAMESPACE

#

Public Class Methods

new( i = nil, run_already = true ) { || ... } click to toggle source
#

initialize

#
# File lib/rbt/utility_scripts/url.rb, line 31
def initialize(
    i           = nil,
    run_already = true
  )
  reset
  set_find_this_program(i)
  if block_given?
    yielded = yield
    case yielded
    when :be_quiet
      @be_verbose = false
    end
  end
  run if run_already
end

Public Instance Methods

array_urls?() click to toggle source
#

array_urls?

This method will return the URLs in Array format.

#
# File lib/rbt/utility_scripts/url.rb, line 142
def array_urls?
  [url1, url2]
end
Also aliased as: result
consider_reporting_url2() click to toggle source
#

consider_reporting_url2

We will try to report the second URL, aka url2.

As of December 2017, if url2 does not exist BUT a homepage url exists, we will use that one instead.

#
# File lib/rbt/utility_scripts/url.rb, line 179
def consider_reporting_url2
  if url2? # <- Prevent nil entries here.
    # ===================================================================== #
    # Check whether there is a homepage-entry, which is not empty - but
    # only use it if url2? is empty. This allows us to use the homepage
    # entry when the cookbook file in question does not have a url2
    # entry set.
    # ===================================================================== #
    if homepage? and !homepage.empty? and url2?.empty?
      e "homepage: #{homepage?.to_s}"
      use_this_as_xorg_buffer(homepage?)
    elsif !url2?.empty?
      result = ''.dup
      result << 'url2: ' if be_verbose?
      result << url2?.to_s
      e result
      use_this_as_xorg_buffer(url2?)
    end
  end
end
determine_dataset( search_for = search_for? ) click to toggle source
#

determine_dataset

#
# File lib/rbt/utility_scripts/url.rb, line 126
def determine_dataset(
    search_for = search_for?
  )
  if RBT.does_include?(search_for) # In this case, we can search for it.
    @dataset = RBT::Cookbooks::Cookbook.new(search_for) { :bypass_menu_check }
  else # Else it was not included.
    opnn; e "The search_term `#{sfancy(search_for)}` is not included."
    exit
  end
end
feedback_urls() click to toggle source
#

feedback_urls

#
# File lib/rbt/utility_scripts/url.rb, line 210
def feedback_urls
  if url1?.empty?
    e "url.rb: We did not find `"+search_for?+"`." if be_verbose?
  else 
    use_this_as_xorg_buffer(url1?)
    result = ''.dup
    result << 'url1: ' if be_verbose?
    result << url1?.to_s
    if be_verbose?
      e result
      consider_reporting_url2 # Delegate to this method.
    end
  end
end
find?()
Alias for: search_for?
homepage()
Alias for: homepage?
homepage?() click to toggle source
#

homepage?

#
# File lib/rbt/utility_scripts/url.rb, line 167
def homepage?
  @dataset.homepage?
end
Also aliased as: homepage
reset() click to toggle source
#

reset

#
Calls superclass method RBT::Base#reset
# File lib/rbt/utility_scripts/url.rb, line 50
def reset
  super()
  @be_verbose = true # Explicitely set it here.
  @dataset = nil
  @namespace = NAMESPACE
end
result()
Alias for: array_urls?
return_main_url()
Alias for: url1?
return_second_url()
Alias for: url2?
run() click to toggle source
#

run

#
# File lib/rbt/utility_scripts/url.rb, line 228
def run
  tell_the_user_what_we_seek
  determine_dataset
  feedback_urls
end
search_for?() click to toggle source
#

search_for?

#
# File lib/rbt/utility_scripts/url.rb, line 119
def search_for?
  @find_this_program
end
Also aliased as: find?
search_for_url(i)
set_find_this_program(i) click to toggle source
#

set_find_this_program

Use this method to designate which program we wish to find the URL for.

#
# File lib/rbt/utility_scripts/url.rb, line 62
def set_find_this_program(i)
  i = i.to_s.strip
  i.delete!('-') if i.include? '-' # Since 05.11.2011
  i.delete!('/') if i.include? '/'
  i.sub!(/\.yml$/,'') if i.end_with? '.yml'
  case i # case tag
  when 'PWD','pwd'
    i = File.basename(Dir.pwd+'/')
  end unless File.exist? i
  i = i.downcase # Since 24.09.2014.
  # ======================================================================= #
  # Check for a Cookbook-alias next:
  # ======================================================================= #
  if RBT.is_an_alias?(i)
    i = RBT.find_cookbook_alias_for(i)
  end unless RBT.has_this_program?(i) # This check is necessary so that "ruby" won't become rubysqlite.
  # ======================================================================= #
  # If the input was not found, then we also check for 'lib' as prefix.
  #
  # This will correct commands such as "url memcached" into
  # "url libmemcached".
  # ======================================================================= #
  unless RBT.does_include? i
    # ===================================================================== #
    # Check a +lib variant here.
    # ===================================================================== #
    if RBT.does_include? 'lib'+i
      i.prepend('lib')
    # ===================================================================== #
    # Check a -lib variant here.
    # ===================================================================== #
    elsif RBT.does_include? i.sub(/^lib/,'')
      i.sub!(/^lib/,'')
    end
  end
  if i.empty? and
     is_on_roebe? and
     return_pwd.include?(source_directory?)
    i = File.basename(return_pwd)
  end
  @find_this_program = i
end
Also aliased as: search_for_url
tell_the_user_what_we_seek( be_verbose = be_verbose? ) click to toggle source
#

tell_the_user_what_we_seek

#
# File lib/rbt/utility_scripts/url.rb, line 108
def tell_the_user_what_we_seek(
    be_verbose = be_verbose?
  )
  if be_verbose
    opnn; e "Seeking URLs to `#{sfancy(search_for?)}` next."
  end
end
url()
Alias for: url2?
url1()
Alias for: url1?
url1?() click to toggle source
#

url1?

#
# File lib/rbt/utility_scripts/url.rb, line 149
def url1?
  @dataset.url1?
end
Also aliased as: return_main_url, url1
url2()
Alias for: url2?
url2?() click to toggle source
#

url2?

#
# File lib/rbt/utility_scripts/url.rb, line 157
def url2?
  @dataset.url2?
end
Also aliased as: return_second_url, url, url?, url2
url?()
Alias for: url2?
use_this_as_xorg_buffer(i) click to toggle source
#

use_this_as_xorg_buffer

#
# File lib/rbt/utility_scripts/url.rb, line 203
def use_this_as_xorg_buffer(i)
  XorgBuffer[i]
end