class Rasam::PairRank
Attributes
decisions[R]
Public Class Methods
new(options)
click to toggle source
# File lib/rasam.rb, line 37 def initialize(options) @options = options @decisions = [] @votes = Hash.new(0) @combination = Combination.new(@options) end
Public Instance Methods
break_tie(pair, choice, criteria)
click to toggle source
# File lib/rasam.rb, line 62 def break_tie(pair, choice, criteria) make_rational_choice(pair, choice, criteria) end
combination()
click to toggle source
# File lib/rasam.rb, line 48 def combination @combination.pair end
combinations()
click to toggle source
# File lib/rasam.rb, line 44 def combinations @options.combination(2).to_a end
make_rational_choice(pair, choice, criteria)
click to toggle source
# File lib/rasam.rb, line 66 def make_rational_choice(pair, choice, criteria) rc = RationalChoice.new(pair, choice, criteria) make(rc) end
score_for(choice)
click to toggle source
# File lib/rasam.rb, line 52 def score_for(choice) @votes[choice] end
tied_pair()
click to toggle source
# File lib/rasam.rb, line 56 def tied_pair return [] if zeros? find_tie end
Private Instance Methods
find_tie()
click to toggle source
# File lib/rasam.rb, line 104 def find_tie result = [] combinations.each do |combination| if tie(combination) result = combination break end end result end
has_tie?()
click to toggle source
# File lib/rasam.rb, line 91 def has_tie? !tied_pair.empty? end
make(rational_choice)
click to toggle source
# File lib/rasam.rb, line 86 def make(rational_choice) store(rational_choice) vote_for(rational_choice) end
store(rational_choice)
click to toggle source
For display at the end of the Pair Ranking process
# File lib/rasam.rb, line 100 def store(rational_choice) @decisions << rational_choice end
tie(combination)
click to toggle source
# File lib/rasam.rb, line 80 def tie(combination) first = score_for(combination[0]) second = score_for(combination[1]) first == second end
vote_for(rational_choice)
click to toggle source
# File lib/rasam.rb, line 95 def vote_for(rational_choice) @votes[rational_choice.choice] += 1 end
zeros?()
click to toggle source
All choices with 0 scores mean the Pair Ranking process has not begun
# File lib/rasam.rb, line 75 def zeros? list = @options.collect{|choice| score_for(choice)} list.uniq == [0] end