X-Git-Url: https://projects.mako.cc/source/rubyvote/blobdiff_plain/56dd8bed5abf1ab2379cae2b891ce3b4b2c5e9b0..f850a85716a7015d7df7057701482901069b2d88:/lib/rubyvote/condorcet.rb diff --git a/lib/rubyvote/condorcet.rb b/lib/rubyvote/condorcet.rb index f4ed7b7..96a103b 100644 --- a/lib/rubyvote/condorcet.rb +++ b/lib/rubyvote/condorcet.rb @@ -33,6 +33,19 @@ class CondorcetVote < ElectionVote + def initialize(votes=nil) + unless defined?(@candidates) + @candidates = Array.new + votes.each do |vote_row| + vote_row = vote_row.flatten if vote_row.class == Array + vote_row.each do |vote| + @candidates << vote unless @candidates.include?(vote) + end + end + end + super(votes) + end + def tally_vote(vote=nil) vote.each_with_index do |winner, index| @@ -63,13 +76,8 @@ class CondorcetVote < ElectionVote # make sure we have a comparable object @votes[loser][winner] = 0 unless @votes[loser].has_key?( winner ) - - @candidates << loser unless @candidates.include?( loser ) end end - - @candidates << winner unless @candidates.include?( winner ) || - winner.class == Array end end