Class: Decidim::Forms::Admin::QuestionnaireAnswerPresenter

Inherits:
SimpleDelegator
  • Object
show all
Includes:
TranslatableAttributes
Defined in:
app/presenters/decidim/forms/admin/questionnaire_answer_presenter.rb

Overview

Presenter for questionnaire answer

Instance Method Summary collapse

Instance Method Details

#answerObject



14
15
16
# File 'app/presenters/decidim/forms/admin/questionnaire_answer_presenter.rb', line 14

def answer
  __getobj__.fetch(:answer)
end

#attachmentsObject



45
46
47
48
49
# File 'app/presenters/decidim/forms/admin/questionnaire_answer_presenter.rb', line 45

def attachments
  (:ul) do
    safe_join(answer.attachments.map { |a| pretty_attachment(a) })
  end
end

#bodyObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/presenters/decidim/forms/admin/questionnaire_answer_presenter.rb', line 26

def body
  return answer.body if answer.body.present?
  return attachments if answer.attachments.any?
  return "-" if answer.choices.empty?

  choices = answer.choices.map do |choice|
    {
      answer_option_body: choice.try(:answer_option).try(:translated_body),
      choice_body: body_or_custom_body(choice)
    }
  end

  return choice(choices.first) if answer.question.question_type == "single_option"

  (:ul) do
    safe_join(choices.map { |c| choice(c) })
  end
end

#questionObject



22
23
24
# File 'app/presenters/decidim/forms/admin/questionnaire_answer_presenter.rb', line 22

def question
  translated_attribute(answer.question.body)
end

#view_contextObject



18
19
20
# File 'app/presenters/decidim/forms/admin/questionnaire_answer_presenter.rb', line 18

def view_context
  __getobj__.fetch(:view_context, ActionController::Base.new.view_context)
end