Class: Poll

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Diaspora::Federated::Base, Diaspora::Guid
Defined in:
app/models/poll.rb

Instance Method Summary collapse

Methods included from Diaspora::Guid

included, #set_guid

Methods included from Diaspora::Federated::Base

included

Instance Method Details

#already_participated?(user) ⇒ Boolean


38
39
40
# File 'app/models/poll.rb', line 38

def already_participated?(user)
  poll_participations.where(:author_id => user.person.id).present?
end

#as_json(options = {}) ⇒ Object


24
25
26
27
28
29
30
31
32
# File 'app/models/poll.rb', line 24

def as_json(options={})
  {
    :poll_id => self.id,
    :post_id => self.status_message.id,
    :question => self.question,
    :poll_answers => self.poll_answers,
    :participation_count => self.participation_count,
  }
end

#enough_poll_answersObject


20
21
22
# File 'app/models/poll.rb', line 20

def enough_poll_answers
  errors.add(:poll_answers, I18n.t("activerecord.errors.models.poll.attributes.poll_answers.not_enough_poll_answers")) if poll_answers.size < 2
end

#participation_countObject


34
35
36
# File 'app/models/poll.rb', line 34

def participation_count
  poll_answers.sum("vote_count")
end