Sha256: cf33b543b2161a56c56ca31ff088a613578f084ae3152e1ea259c088156e4ca7

Contents?: true

Size: 977 Bytes

Versions: 8

Compression:

Stored size: 977 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Forms
    module Admin
      #
      # Presenter for questionnaire answer
      #
      class QuestionnaireAnswerPresenter < Rectify::Presenter
        include Decidim::TranslatableAttributes

        attribute :answer, Decidim::Forms::Answer

        def question
          translated_attribute(answer.question.body)
        end

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

          choices = answer.choices.map do |choice|
            choice.try(:custom_body) || choice.try(:body)
          end

          return choices.first if answer.question.question_type == "single_option"

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

        private

        def choice(choice_body)
          content_tag :li do
            choice_body
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
decidim-forms-0.23.6 app/presenters/decidim/forms/admin/questionnaire_answer_presenter.rb
decidim-forms-0.23.5 app/presenters/decidim/forms/admin/questionnaire_answer_presenter.rb
decidim-forms-0.23.4 app/presenters/decidim/forms/admin/questionnaire_answer_presenter.rb
decidim-forms-0.23.3 app/presenters/decidim/forms/admin/questionnaire_answer_presenter.rb
decidim-forms-0.23.2 app/presenters/decidim/forms/admin/questionnaire_answer_presenter.rb
decidim-forms-0.23.1 app/presenters/decidim/forms/admin/questionnaire_answer_presenter.rb
decidim-forms-0.23.1.rc1 app/presenters/decidim/forms/admin/questionnaire_answer_presenter.rb
decidim-forms-0.23.0 app/presenters/decidim/forms/admin/questionnaire_answer_presenter.rb