class RBT::ExclusiveLogic

Public Class Methods

new( string_to_check = '', run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/misc/exclusive_logic.rb, line 27
def initialize(
    string_to_check = '',
    run_already     = true
  )
  reset
  assign_string(string_to_check)
  scan_string if run_already
end

Public Instance Methods

assign_string(s) click to toggle source
#

assign_string

Perform sanitizing stuff, then assign to @string.

#
# File lib/rbt/misc/exclusive_logic.rb, line 86
def assign_string(s)
  @string = s.delete(N).squeeze(' ').chomp
end
debug() click to toggle source
#

debug

#
# File lib/rbt/misc/exclusive_logic.rb, line 158
def debug
  opne "Have we found any Problems in the logic given? "\
       "#{simp(vt(@problems.to_s).delete('.'))}."
  pp @duplicates unless @duplicates.empty?
  pp @string
end
duplicates()
Alias for: duplicates?
duplicates?() click to toggle source
#

duplicates?

#
# File lib/rbt/misc/exclusive_logic.rb, line 168
def duplicates?
  @duplicates
end
Also aliased as: duplicates
force_add(i) click to toggle source
#

force_add

This method will force-add a specific configure option.

Additionally, it will replace any contradictory configuration options, and thus guarantees that our resulting string will be sane.

#
# File lib/rbt/misc/exclusive_logic.rb, line 135
def force_add(i)
  i = i.flatten.join(' ') if i.is_a? Array
  i = sanitize_string(i).join
  @string.gsub!(/#{i}/,'') # remove it if it already is part of our string.
  if i.include? 'disable'
    @string.gsub!(/#{i.gsub(/disable/, 'enable')}/,'')
  elsif i.include? 'enable'
    @string.gsub!(/#{i.gsub(/enable/, 'disable')}/,'')
  end
  @string << ' '+i
  scan_string
end
has_duplicate?(array) click to toggle source
#

has_duplicate?

#
# File lib/rbt/misc/exclusive_logic.rb, line 93
def has_duplicate?(array)
  _ = false # This will become the return value.
  # ======================================================================= #
  # Get rid of all "enable" and "disable" parts next.
  # ======================================================================= #
  copy = array.map {|entry| entry.gsub(/enable/,'').gsub(/disable/,'') }
  _ = true if copy.uniq
  _
end
no_problems() click to toggle source
#

no_problems

Set no problems here. This is used just for debugging.

#
# File lib/rbt/misc/exclusive_logic.rb, line 70
def no_problems
  @problems = false
end
problems()
Alias for: problems?
problems?() click to toggle source
#

problems?

#
# File lib/rbt/misc/exclusive_logic.rb, line 77
def problems?
  @problems
end
Also aliased as: problems
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/misc/exclusive_logic.rb, line 39
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @string
  # ======================================================================= #
  @string = ''.dup
  # ======================================================================= #
  # === @problems
  #
  # This is a boolean variable, so it can be true or false.
  # ======================================================================= #
  @problems = false
  # ======================================================================= #
  # === @duplicates
  # ======================================================================= #
  @duplicates = [] # An Array.
end
return_duplicates(i) click to toggle source
#

return_duplicates

This method will return keys which are duplicates (or in other words, all entries which occur more than once). ” is ignored though as I can’t see it being useful for anything much really.

The file “rbt/lib/rbt/exclusive_logic.rb” needs this method.

Example:

['foo', 'bar', 'ble', 'foo', 'ble', 'go','yo','',''].return_duplicates # => ["ble", "foo"]
#
# File lib/rbt/misc/exclusive_logic.rb, line 207
def return_duplicates(i)
  return_value = []
  hash = Hash.new(0)
  i.each { |word| hash[word] += 1 }
  hash.select {|key, value|
    return_value << key if value > 1 and ! key.empty?
  }
  return_value = [] if return_value.empty?
  return return_value
end
run() click to toggle source
#

run

#
# File lib/rbt/misc/exclusive_logic.rb, line 221
def run
  scan_string
end
sanitize_string(i) click to toggle source
#

sanitize_string

This method replaces ‘ ’ with ‘ ’ and then goes to split at ‘ ’ before it returns an array.

#
# File lib/rbt/misc/exclusive_logic.rb, line 123
def sanitize_string(i)
  i.squeeze(' ').split(' ') if i
end
scan_string() click to toggle source
#

scan_string

This is the actual powerhorse. It also sets the @problems variable in case it encountered a problem.

#
# File lib/rbt/misc/exclusive_logic.rb, line 178
def scan_string
  all_words = split_up_string_properly # call this method, which is defined in this file here.
  if has_duplicate? all_words # if true then we must have duplicates.
    @problems = true
    all_duplicates = return_duplicates(all_words)
    unless all_duplicates.empty?
      all_duplicates.each {|duplicate|
        @duplicates << splitted.select {|_| _ =~ /#{duplicate}/ }
      }
      @duplicates.flatten!
      @duplicates.map! {|_| _ = '--'+_ }
    end
  end
end
split_up_string_properly() click to toggle source
#

split_up_string_properly

The .map is used to omit the leading ./configure word. We use .squeeze to get rid of multiple ‘ ’

#
# File lib/rbt/misc/exclusive_logic.rb, line 109
def split_up_string_properly
  splitted = sanitize_string(@string) # we work on @string.
  all_words = splitted.map {|_| 
    _.split('-').join('').squeeze(' ').gsub(/\.\/configure/,'')
   }.select {|_| ! _.empty?}
  return all_words
end
string()
Alias for: string?
string?() click to toggle source
#

string?

#
# File lib/rbt/misc/exclusive_logic.rb, line 61
def string?
  @string
end
Also aliased as: string