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

Inherits:
Rectify::Presenter
  • 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

#attachmentsObject



37
38
39
40
41
# File 'app/presenters/decidim/forms/admin/questionnaire_answer_presenter.rb', line 37

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

#bodyObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/presenters/decidim/forms/admin/questionnaire_answer_presenter.rb', line 18

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



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

def question
  translated_attribute(answer.question.body)
end