class RBT::Headers

Public Class Methods

[](i = '') click to toggle source
#

RBT::Headers[]

#
# File lib/rbt/headers/headers.rb, line 141
def self.[](i = '')
  new(i)
end
new( commandline_arguments = nil, run_already = true ) click to toggle source
#

initialize

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

Public Instance Methods

check_whether_the_input_is_a_header_file() click to toggle source
#

check_whether_the_input_is_a_header_file

#
# File lib/rbt/headers/headers.rb, line 112
def check_whether_the_input_is_a_header_file
  first_argument = first_argument?
  unless first_argument.end_with? '.h'
    e steelblue(first_argument)+' does not seem to be a .h file.'
  end
end
load_up_the_registered_headers( i = RBT.file_registered_headers ) click to toggle source
#

load_up_the_registered_headers

This method will simply load the registered .h (header) files, from the yaml file.

#
# File lib/rbt/headers/headers.rb, line 62
def load_up_the_registered_headers(
    i = RBT.file_registered_headers
  )
  @registered_headers = YAML.load_file(i)
end
match?() click to toggle source
#

match?

#
# File lib/rbt/headers/headers.rb, line 122
def match?
  @match
end
report() click to toggle source
#

report

#
# File lib/rbt/headers/headers.rb, line 100
def report
  if @match
    _ = first_argument?
    e "#{rev}The given input #{steelblue(_)} "\
      "matches to the program #{lightblue(@match)}. "\
      "(#{olivedrab(_)} #{tomato('→')} #{mediumpurple(@match)})"
  end
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/headers/headers.rb, line 41
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @match
  # ======================================================================= #
  @match = nil
  # ======================================================================= #
  # === @do_report
  #
  # By default this class will not report.
  # ======================================================================= #
  @do_report = false
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/headers/headers.rb, line 129
def run
  check_whether_the_input_is_a_header_file
  load_up_the_registered_headers
  try_to_find_a_match_for_the_given_input
  if @do_report
    report
  end
end
try_to_find_a_match_for_the_given_input() click to toggle source
#

try_to_find_a_match_for_the_given_input

#
# File lib/rbt/headers/headers.rb, line 71
def try_to_find_a_match_for_the_given_input
  first_argument = first_argument?
  if first_argument.nil?
    e "#{rev}Please provide some input, such as #{steelblue('ao.h')}."
  else
    # ===================================================================== #
    # First check whether such a file exists in the registered headers.
    # ===================================================================== #
    if @registered_headers.has_key? first_argument
      @match = @registered_headers[first_argument]
    else # else we need to find any .header file.
      if @registered_headers.keys.any? {|entry| entry.end_with?("/#{first_argument}") }
        selection = @registered_headers.select {|header_file, name_of_the_program_at_hand|
          header_file.end_with?("/#{first_argument}")
        }
        if selection.empty?
          e "No match has been found for the given "\
            "input #{steelblue(first_argument)}."
        else
          @match = selection[selection.keys.first]
        end
      end
    end
  end
end