Class: PollPresenter

Inherits:
BasePresenter show all
Defined in:
app/presenters/poll_presenter.rb

Instance Attribute Summary

Attributes inherited from BasePresenter

#current_user

Instance Method Summary collapse

Methods inherited from BasePresenter

as_collection, #method_missing, new

Constructor Details

#initialize(poll, current_user = nil) ⇒ PollPresenter

Returns a new instance of PollPresenter.


4
5
6
7
8
# File 'app/presenters/poll_presenter.rb', line 4

def initialize(poll, current_user=nil)
  super(poll, current_user)

  @participation = participation_answer(current_user) if current_user
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class BasePresenter

Instance Method Details

#as_api_jsonObject


10
11
12
13
14
15
16
17
18
# File 'app/presenters/poll_presenter.rb', line 10

def as_api_json
  {
    guid:                 guid,
    participation_count:  participation_count,
    question:             question,
    already_participated: @participation.present?,
    poll_answers:         answers_collection_as_api_json(poll_answers)
  }
end