summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
ad05e67)
## the CloneproofSSDVote classes but should not be used directly.
class CondorcetVote < ElectionVote
## the CloneproofSSDVote classes but should not be used directly.
class CondorcetVote < ElectionVote
attr_accessor :results
def initialize(votes=nil)
attr_accessor :results
def initialize(votes=nil)
## directly.
class CondorcetResult < ElectionResult
## directly.
class CondorcetResult < ElectionResult
def initialize(voteobj=nil)
unless voteobj and voteobj.kind_of?( CondorcetVote )
raise ArgumentError, "You must pass a CondorcetVote array.", caller
end
super(voteobj)
def initialize(voteobj=nil)
unless voteobj and voteobj.kind_of?( CondorcetVote )
raise ArgumentError, "You must pass a CondorcetVote array.", caller
end
super(voteobj)
+ @matrix = voteobj.votes
def defeats(candidates=nil, votes=nil)
candidates = @election.candidates unless candidates
votes = @election.votes unless votes
def defeats(candidates=nil, votes=nil)
candidates = @election.candidates unless candidates
votes = @election.votes unless votes
class PluralityResult < ElectionResult
attr_reader :ranked_candidates
class PluralityResult < ElectionResult
attr_reader :ranked_candidates
def initialize(voteobj=nil)
super(voteobj)
def initialize(voteobj=nil)
super(voteobj)
b[1] <=> a[1]
end.collect {|a| a[0]}
b[1] <=> a[1]
end.collect {|a| a[0]}
+ @points = @election.votes
+
# winners are anyone who has the same number of votes as the
# first person
@winners = @ranked_candidates.find_all do |i|
# winners are anyone who has the same number of votes as the
# first person
@winners = @ranked_candidates.find_all do |i|
def tally_vote(vote)
points = candidates.length - 1
vote.each do |candidate|
def tally_vote(vote)
points = candidates.length - 1
vote.each do |candidate|
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
class BordaResult < ElectionResult
attr_reader :ranked_candidates
class BordaResult < ElectionResult
attr_reader :ranked_candidates
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]}
@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