Class: Candidate

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/candidate.rb

Instance Method Summary collapse

Instance Method Details

#number_of_votersObject



18
19
20
# File 'app/models/candidate.rb', line 18

def number_of_voters
  candidate_votes.count
end

#number_of_votesObject



14
15
16
# File 'app/models/candidate.rb', line 14

def number_of_votes
  candidate_votes.where(:voted => true).count
end

#percentageObject



9
10
11
12
# File 'app/models/candidate.rb', line 9

def percentage
  return 0 if number_of_votes.zero?
  100 * number_of_votes / number_of_voters
end