Class: Decidim::Exporters::FormPDF::QuestionnaireResponsePresenter
Instance Method Summary
collapse
#question, #response, #view_context
Instance Method Details
#body ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/decidim/exporters/form_pdf.rb', line 27
def body
return { string: response.body } if response.body.present?
return { attachments: response.attachments } if response.attachments.any?
return { string: "-" } if response.choices.empty?
choices = response.choices.map do |choice|
{
response_option_body: choice.try(:response_option).try(:translated_body),
choice_body: body_or_custom_body(choice),
matrix_row_body: choice.try(:matrix_row).try(:body) ? translated_attribute(choice.matrix_row.body) : nil
}
end
return { single_option: choice(choices.first) } if response.question.question_type == "single_option"
{ multiple_option: choices.map { |c| choice(c) } }
end
|
#choice(choice_hash) ⇒ Object
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/decidim/exporters/form_pdf.rb', line 14
def choice(choice_hash)
if choice_hash[:matrix_row_body].present?
row_text = choice_hash[:matrix_row_body]
option_text = choice_hash[:response_option_body]
custom_text = choice_hash[:choice_body].present? ? " (#{choice_hash[:choice_body]})" : ""
"#{row_text}: #{option_text}#{custom_text}"
else
render_body_for choice_hash
end
end
|