]> projects.mako.cc - selectricity-live/blobdiff - lib/rubyvote/positional.rb
Disallow identical candidates to be added to a quickvote. Differently cased identical...
[selectricity-live] / lib / rubyvote / positional.rb
index 11e8a499a9fdceb4a517677545017bb829af8cb8..056194b519dc88f2a79adc3617bf95f250fa3310 100644 (file)
@@ -38,15 +38,20 @@ class BordaVote < ElectionVote
     end
     super(votes)
   end
     end
     super(votes)
   end
-
+   
   def tally_vote(vote)
     points = candidates.length - 1
     vote.each do |candidate|
   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
       points -= 1
     end
   end
-
+  
   def verify_vote(vote=nil)
     vote.instance_of?( Array ) and
       vote == vote.uniq
   def verify_vote(vote=nil)
     vote.instance_of?( Array ) and
       vote == vote.uniq
@@ -58,10 +63,13 @@ class BordaVote < ElectionVote
 end
 
 class BordaResult < ElectionResult
 end
 
 class BordaResult < ElectionResult
+  attr_reader :ranked_candidates
+  attr_reader :points
+  
   def initialize(voteobj=nil)
     super(voteobj)
     votes = @election.votes
   def initialize(voteobj=nil)
     super(voteobj)
     votes = @election.votes
-
+    
     @ranked_candidates = votes.sort do |a, b|
       b[1] <=> a[1]
     end.collect {|i| i[0]}
     @ranked_candidates = votes.sort do |a, b|
       b[1] <=> a[1]
     end.collect {|i| i[0]}
@@ -69,6 +77,8 @@ class BordaResult < ElectionResult
     @winners = @ranked_candidates.find_all do |i|
       votes[i] == votes[@ranked_candidates[0]]
     end
     @winners = @ranked_candidates.find_all do |i|
       votes[i] == votes[@ranked_candidates[0]]
     end
+    
+    @points = @election.votes
   end
 
 end
   end
 
 end

Benjamin Mako Hill || Want to submit a patch?