Sha256: d39fa43655b8333081fbe8227bc6fee7229da7d26679ed226cd987b852e9f5b7
Contents?: true
Size: 978 Bytes
Versions: 12
Compression:
Stored size: 978 Bytes
Contents
# frozen_string_literal: true module Decidim module Forms # The data store for a Question in the Decidim::Forms component. class Question < Forms::ApplicationRecord TYPES = %w(short_answer long_answer single_option multiple_option sorting).freeze belongs_to :questionnaire, class_name: "Questionnaire", foreign_key: "decidim_questionnaire_id" has_many :answer_options, class_name: "AnswerOption", foreign_key: "decidim_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
12 entries across 12 versions & 1 rubygems