From e68b817c4ef0e16cc4c9b0b4dbc5b7feb7d2a112 Mon Sep 17 00:00:00 2001 From: Benjamin Mako Hill Date: Tue, 14 Aug 2007 18:40:58 +0000 Subject: [PATCH 1/1] Fixed bug in Borda that was counting the votes incorrect very frequently. Thanks Justin Sharps! git-svn-id: svn://rubyforge.org/var/svn/rubyvote/trunk@28 1440c7f4-e209-0410-9a04-881b5eb134a8 --- lib/rubyvote/positional.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/rubyvote/positional.rb b/lib/rubyvote/positional.rb index 11e8a49..3de3fb2 100644 --- a/lib/rubyvote/positional.rb +++ b/lib/rubyvote/positional.rb @@ -42,7 +42,12 @@ class BordaVote < ElectionVote def tally_vote(vote) points = candidates.length - 1 vote.each do |candidate| - @votes[candidate] = points + #if the candidate exist, add the points, otherwise assign them + if @votes.has_key?(candidate) + @votes[candidate] += points + else + @votes[candidate] = points + end points -= 1 end end @@ -58,6 +63,8 @@ class BordaVote < ElectionVote end class BordaResult < ElectionResult + attr_reader :ranked_candidates + def initialize(voteobj=nil) super(voteobj) votes = @election.votes -- 2.39.5