Class: Poll

Inherits:
ApplicationRecord show all
Includes:
Diaspora::Federated::Base, Diaspora::Federated::Fetchable, Diaspora::Fields::Guid
Defined in:
app/models/poll.rb

Instance Method Summary collapse

Methods included from Diaspora::Fields::Guid

included, #set_guid

Methods included from Diaspora::Federated::Base

#object_to_receive, #subscribers

Instance Method Details

#as_json(options = {}) ⇒ Object


27
28
29
30
31
32
33
34
35
# File 'app/models/poll.rb', line 27

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

#enough_poll_answersObject


23
24
25
# File 'app/models/poll.rb', line 23

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_answer(user) ⇒ Object


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

def participation_answer(user)
  poll_participations.find_by(author_id: user.person.id)
end

#participation_countObject


41
42
43
# File 'app/models/poll.rb', line 41

def participation_count
  poll_answers.sum("vote_count")
end