X-Git-Url: https://projects.mako.cc/source/selectricity/blobdiff_plain/04f827dd4647f3a7d6e5bd8f5e9083c730a8dccc..8afec3c5b4896fd7665e6527f3acb7c7afac7e47:/lib/rubyvote/election.rb diff --git a/lib/rubyvote/election.rb b/lib/rubyvote/election.rb index fc61840..66e4c2a 100644 --- a/lib/rubyvote/election.rb +++ b/lib/rubyvote/election.rb @@ -34,7 +34,7 @@ class ElectionVote attr_reader :votes attr_reader :candidates - + def initialize(votes=nil) @votes = Hash.new unless defined?(@votes) @candidates = Array.new unless defined?(@candidates) @@ -61,6 +61,11 @@ class ElectionVote def tally_vote self.verify_vote(vote) end + + def filter_out(winner) + @candidates.delete_if {|x| winner.winners.include?(x)} + end + end class PluralityVote < ElectionVote @@ -70,7 +75,7 @@ class PluralityVote < ElectionVote protected def verify_vote(vote=nil) - vote ? true : false + not vote.instance_of?( Array ) end def tally_vote(candidate) @@ -109,7 +114,8 @@ end class ElectionResult attr_reader :winners - + attr_reader :election + def initialize(voteobj=nil) unless voteobj and voteobj.kind_of?( ElectionVote ) raise ArgumentError, "You must pass a ElectionVote array.", caller