class RBT::Cookbooks::Url

Public Class Methods

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

initialize

#
# File lib/rbt/cookbooks/url/url.rb, line 27
def initialize(
    i           = nil,
    run_already = true
  )
  reset
  set_find_these_programs(i)
  # ======================================================================= #
  # === Handle blocks given to this method
  # ======================================================================= #
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # === :be_quiet
    # ===================================================================== #
    when :be_quiet
      set_be_quiet
    # ===================================================================== #
    # === :show_the_homepage_as_well
    # ===================================================================== #
    when :show_the_homepage_as_well
      @show_the_homepage = true
    # ===================================================================== #
    # === :show_the_homepage_as_well_and_the_git_URL_should_it_exist
    # ===================================================================== #
    when :show_the_homepage_as_well_and_the_git_URL_should_it_exist
      @show_the_homepage = true
      @show_the_git_URL_as_well_should_it_exist = true
    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/cookbooks/url/url.rb, line 160
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/cookbooks/url/url.rb, line 204
def consider_reporting_url2
  if url2? # ← Prevent nil entries here.
    if !url2?.empty?
      if be_verbose?
        result = ''.dup
        if @show_leading_url_entry
          if use_colours?
            result << skyblue('url2: ')
          else
            result << 'url2: '
          end
        end
        if use_colours?
          result << yellowgreen(url2?.to_s)
        else
          result << url2?.to_s
        end
        e result.strip
        use_this_as_xorg_buffer(url2?)
      end
    end
  end
end
determine_dataset( search_for = search_for? ) click to toggle source
#

determine_dataset

This method will also set the @dataset variable.

#
# File lib/rbt/cookbooks/url/url.rb, line 247
def determine_dataset(
    search_for = search_for?
  )
  if RBT.does_include?(search_for) # In this case, we can search for it.
    @dataset = action(:SanitizeCookbook, search_for) { :fast }
  else # Else it was not included.
    opne "The search_term `#{sfancy(search_for)}#{rev}` is not included."
    exit
  end
end
do_work_on_all_found_programs() click to toggle source
#

do_work_on_all_found_programs

#
# File lib/rbt/cookbooks/url/url.rb, line 335
def do_work_on_all_found_programs
  @find_these_programs.each {|entry|
    set_search_for(entry)
    tell_the_user_what_we_seek
    determine_dataset
    feedback_urls
  }
end
feedback_urls() click to toggle source
#

feedback_urls

#
# File lib/rbt/cookbooks/url/url.rb, line 277
def feedback_urls
  if url1?.nil? or url1?.empty?
    e "url.rb: We did not find `#{search_for?}`." if be_verbose?
  else
    use_this_as_xorg_buffer(url1?)
    result = ''.dup
    if @show_leading_url_entry
      if be_verbose?
        if use_colours?
          result << skyblue('url1: ')
        else
          result << 'url1: '
        end
      else
        result << 'url1: '
      end
    end
    if use_colours?
      result << yellowgreen(url1?.to_s)
    else
      result << url1?.to_s
    end
    e result if be_verbose?
    if be_verbose?
      consider_reporting_url2 # Delegate to this method.
    end
    # ===================================================================== #
    # === Show the homepage as well
    #
    # This allows us to use the homepage entry.
    # ===================================================================== #
    if @show_the_homepage and
       homepage and
      !homepage.empty?
      if use_colours?
        e "#{skyblue('homepage: ')}"+
          yellowgreen(homepage?.to_s)
      else
        e "#homepage: #{homepage?}"
      end
    end
    if @show_the_git_URL_as_well_should_it_exist and
       git_URL? and
      !git_URL?.empty?
      if use_colours?
        e "#{skyblue('git:      ')}"+
          yellowgreen(git_URL?.to_s)
      else
        e "#git: #{git_URL?}"
      end
    end
  end
  e
end
find?()
Alias for: search_for?
git_URL?() click to toggle source
#

git_URL?

#
# File lib/rbt/cookbooks/url/url.rb, line 192
def git_URL?
  @dataset.git_URL?
end
Also aliased as: git_url?
git_url?()
Alias for: git_URL?
homepage()
Alias for: homepage?
homepage?() click to toggle source
#

homepage?

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

reset

#
Calls superclass method RBT::LeanPrototype#reset
# File lib/rbt/cookbooks/url/url.rb, line 63
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @show_the_homepage
  # ======================================================================= #
  @show_the_homepage = false
  # ======================================================================= #
  # === @show_the_git_URL_as_well_should_it_exist
  # ======================================================================= #
  @show_the_git_URL_as_well_should_it_exist = false
  # ======================================================================= #
  # === :be_verbose
  # ======================================================================= #
  set_be_verbose # Explicitely set it here.
  # ======================================================================= #
  # === @dataset
  # ======================================================================= #
  @dataset = nil
  # ======================================================================= #
  # === :search_for
  # ======================================================================= #
  @internal_hash[:search_for] = nil
  # ======================================================================= #
  # === @show_leading_url_entry
  #
  # If this variable is set to true then we will show the leading
  # url1: part.
  # ======================================================================= #
  @show_leading_url_entry = true
  try_to_require_the_xorg_buffer
end
result()
Alias for: array_urls?
return_main_url()
Alias for: url1?
return_second_url()
Alias for: url2?
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/cookbooks/url/url.rb, line 347
def run
  do_work_on_all_found_programs
end
search_for?() click to toggle source
#

search_for?

#
# File lib/rbt/cookbooks/url/url.rb, line 151
def search_for?
  @internal_hash[:search_for]
end
Also aliased as: find?
search_for_url(i)
set_find_these_programs(i) click to toggle source
#

set_find_these_programs

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

#
# File lib/rbt/cookbooks/url/url.rb, line 101
def set_find_these_programs(i)
  i = [i].flatten.compact
  i.map! {|entry|
    entry = entry.to_s.strip
    entry.delete!('-') if entry.include? '-' # Since 05.11.2011
    entry.delete!('/') if entry.include? '/'
    entry.sub!(/\.yml$/,'') if entry.end_with? '.yml'
    case entry # case tag
    when /^PWD$/i
      entry = File.basename(return_pwd)
    end unless File.exist? entry
    entry.downcase! # Since as of 24.09.2014.
    # ======================================================================= #
    # Check for a Cookbook-alias next:
    # ======================================================================= #
    if RBT.is_an_alias?(entry)
      entry = RBT.find_cookbook_alias_for(entry)
    end unless RBT.has_this_program?(entry) # 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? entry
      # ===================================================================== #
      # Check a +lib variant here.
      # ===================================================================== #
      if RBT.does_include? "lib#{entry}"
        entry.prepend('lib')
      # ===================================================================== #
      # Check a -lib variant here.
      # ===================================================================== #
      elsif RBT.does_include? entry.sub(/^lib/,'')
        entry.sub!(/^lib/,'')
      end
    end
    if entry.empty? and
       is_on_roebe? and
       return_pwd.include?(source_directory?)
      entry = File.basename(return_pwd)
    end
    entry
  }
  @find_these_programs = i
end
Also aliased as: search_for_url
set_search_for(i) click to toggle source
#

set_search_for

#
# File lib/rbt/cookbooks/url/url.rb, line 261
def set_search_for(i)
  @internal_hash[:search_for] = i
end
tell_the_user_what_we_seek( be_verbose = be_verbose? ) click to toggle source
#

tell_the_user_what_we_seek

This method notifies the user for which particular program this class will try to obtain the associated homepage.

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

url1?

#
# File lib/rbt/cookbooks/url/url.rb, line 167
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/cookbooks/url/url.rb, line 175
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

This method has to account for “xsel” existing or not.

#
# File lib/rbt/cookbooks/url/url.rb, line 270
def use_this_as_xorg_buffer(i)
  set_xorg_buffer(i)
end