class RBT::ExclusiveLogic
Public Class Methods
Public Instance Methods
assign_string(s)
click to toggle source
debug()
click to toggle source
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
problems?()
click to toggle source
Also aliased as: problems
reset()
click to toggle source
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
Calls superclass method
RBT::LeanPrototype#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
sanitize_string(i)
click to toggle source
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