Class: Ballot
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Ballot
- Defined in:
- app/models/ballot.rb
Instance Method Summary collapse
- #nonvoting_members ⇒ Object
- #number_of_voters ⇒ Object
- #number_of_votes ⇒ Object
- #open_for_voting? ⇒ Boolean
- #pretty_date(date) ⇒ Object
- #pretty_end_date ⇒ Object
- #pretty_start_date ⇒ Object
- #start_date_is_before_end_date ⇒ Object
- #too_early_to_vote? ⇒ Boolean
- #too_late_to_vote? ⇒ Boolean
- #voted_on_by?(member) ⇒ Boolean
- #voting_members ⇒ Object
Instance Method Details
#nonvoting_members ⇒ Object
54 55 56 |
# File 'app/models/ballot.rb', line 54 def nonvoting_members Member.all.reject { |member| voted_on_by? member } end |
#number_of_voters ⇒ Object
46 47 48 |
# File 'app/models/ballot.rb', line 46 def number_of_voters ballot_votes.count end |
#number_of_votes ⇒ Object
39 40 41 42 43 44 |
# File 'app/models/ballot.rb', line 39 def number_of_votes sums = ballot_votes.map do |ballot_vote| ballot_vote.candidate_votes.where(:voted => true).count end sums.inject :+ end |
#open_for_voting? ⇒ Boolean
27 28 29 |
# File 'app/models/ballot.rb', line 27 def open_for_voting? start_date <= today && today <= end_date end |
#pretty_date(date) ⇒ Object
23 24 25 |
# File 'app/models/ballot.rb', line 23 def pretty_date(date) date.strftime "%B %e, %Y" end |
#pretty_end_date ⇒ Object
19 20 21 |
# File 'app/models/ballot.rb', line 19 def pretty_end_date pretty_date end_date end |
#pretty_start_date ⇒ Object
15 16 17 |
# File 'app/models/ballot.rb', line 15 def pretty_start_date pretty_date start_date end |
#start_date_is_before_end_date ⇒ Object
59 60 61 62 |
# File 'app/models/ballot.rb', line 59 def start_date_is_before_end_date return if start_date < end_date errors[:start_date] << 'must be after end date' end |
#too_early_to_vote? ⇒ Boolean
31 32 33 |
# File 'app/models/ballot.rb', line 31 def too_early_to_vote? today < start_date end |
#too_late_to_vote? ⇒ Boolean
35 36 37 |
# File 'app/models/ballot.rb', line 35 def too_late_to_vote? end_date < today end |
#voted_on_by?(member) ⇒ Boolean
64 65 66 |
# File 'app/models/ballot.rb', line 64 def voted_on_by?(member) ballot_votes.where(:member_id => member.id, :ballot_id => id).any? end |
#voting_members ⇒ Object
50 51 52 |
# File 'app/models/ballot.rb', line 50 def voting_members Member.all.select { |member| voted_on_by? member } end |