Skip to content

Commit

Permalink
Edited candidate model.
Browse files Browse the repository at this point in the history
  • Loading branch information
andyt committed May 20, 2012
1 parent 75b0828 commit 8645043
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/models/candidate.rb
Expand Up @@ -5,12 +5,25 @@ class Candidate

belongs_to :constituency
belongs_to :party
has_many :votes

alias_method :to_s, :name

def name_and_party
"%s (%s)" % [name, party.name]
end

def share_of_vote
if constituency.vote_count > 0
"%0.1f%%" % (100 * votes.count / constituency.vote_count.to_f)
else
'-'
end
end

def vote_count
@vote_count ||= votes.count
end

end

0 comments on commit 8645043

Please sign in to comment.