Sha256: a69aeecdb958fb185fff4d62862ddf436bfc03fd52c863debcdaa1149e88a8d1

Contents?: true

Size: 988 Bytes

Versions: 17

Compression:

Stored size: 988 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Surveys
    # The data store for a SurveyQuestion in the Decidim::Surveys component.
    class SurveyQuestion < Surveys::ApplicationRecord
      TYPES = %w(short_answer long_answer single_option multiple_option sorting).freeze

      belongs_to :survey, class_name: "Survey", foreign_key: "decidim_survey_id"

      has_many :answer_options,
               class_name: "SurveyAnswerOption",
               foreign_key: "decidim_survey_question_id",
               dependent: :destroy,
               inverse_of: :question

      validates :question_type, inclusion: { in: TYPES }

      def multiple_choice?
        %w(single_option multiple_option sorting).include?(question_type)
      end

      def mandatory_body?
        mandatory? && !multiple_choice?
      end

      def mandatory_choices?
        mandatory? && multiple_choice?
      end

      def number_of_options
        answer_options.size
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
decidim-surveys-0.15.2 app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.15.1 app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.15.0 app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.14.4 app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.14.3 app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.14.2 app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.14.1 app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.13.1 app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.12.2 app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.13.0 app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.12.1 app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.13.0.pre1 app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.12.0 app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.11.2 app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.12.0.pre app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.11.1 app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.11.0.pre1 app/models/decidim/surveys/survey_question.rb