Class: Rasam::PairRank
- Inherits:
-
Object
- Object
- Rasam::PairRank
- Defined in:
- lib/rasam.rb
Instance Attribute Summary collapse
-
#combinations ⇒ Object
readonly
Returns the value of attribute combinations.
-
#decisions ⇒ Object
readonly
Returns the value of attribute decisions.
Instance Method Summary collapse
- #break_tie(pair, choice, criteria) ⇒ Object
-
#initialize(options) ⇒ PairRank
constructor
A new instance of PairRank.
- #make(rational_choice) ⇒ Object
- #make_rational_choice(pair, choice, criteria) ⇒ Object
- #pair_for(choice) ⇒ Object
- #rationale_for(choice) ⇒ Object
- #score_for(choice) ⇒ Object
- #tied_pair ⇒ Object
Constructor Details
#initialize(options) ⇒ PairRank
Returns a new instance of PairRank.
26 27 28 29 30 |
# File 'lib/rasam.rb', line 26 def initialize() @decisions = [] @votes = Hash.new(0) @combinations = .combination(2).to_a end |
Instance Attribute Details
#combinations ⇒ Object (readonly)
Returns the value of attribute combinations.
24 25 26 |
# File 'lib/rasam.rb', line 24 def combinations @combinations end |
#decisions ⇒ Object (readonly)
Returns the value of attribute decisions.
24 25 26 |
# File 'lib/rasam.rb', line 24 def decisions @decisions end |
Instance Method Details
#break_tie(pair, choice, criteria) ⇒ Object
65 66 67 |
# File 'lib/rasam.rb', line 65 def break_tie(pair, choice, criteria) make_rational_choice(pair, choice, criteria) end |
#make(rational_choice) ⇒ Object
32 33 34 35 |
# File 'lib/rasam.rb', line 32 def make(rational_choice) @decisions << rational_choice @votes[rational_choice.choice] += 1 end |
#make_rational_choice(pair, choice, criteria) ⇒ Object
69 70 71 72 |
# File 'lib/rasam.rb', line 69 def make_rational_choice(pair, choice, criteria) rc = RationalChoice.new(pair, choice, criteria) make(rc) end |
#pair_for(choice) ⇒ Object
46 47 48 49 |
# File 'lib/rasam.rb', line 46 def pair_for(choice) decision = @decisions.find{|x| x.choice == choice} decision.pair end |
#rationale_for(choice) ⇒ Object
41 42 43 44 |
# File 'lib/rasam.rb', line 41 def rationale_for(choice) decision = @decisions.find{|x| x.choice == choice} decision.criteria end |
#score_for(choice) ⇒ Object
37 38 39 |
# File 'lib/rasam.rb', line 37 def score_for(choice) @votes[choice] end |
#tied_pair ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rasam.rb', line 51 def tied_pair result = [] @combinations.each do |combination| first = score_for(combination[0]) second = score_for(combination[1]) if tie(first, second) result = combination break end end result end |