X-Git-Url: https://projects.mako.cc/source/selectricity/blobdiff_plain/fc0a6a8d7ea15bcdb27ebdd58721401c7045c6e0..bb6aa392b953e018389843b02f044afd45d8afb9:/lib/rubyvote/election.rb diff --git a/lib/rubyvote/election.rb b/lib/rubyvote/election.rb old mode 100755 new mode 100644 index fc61840..75614e6 --- 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 + vote.instance_of?( String ) 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