Class: Decidim::Forms::Question
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Forms::Question
- Includes:
- TranslatableResource
- Defined in:
- app/models/decidim/forms/question.rb
Overview
The data store for a Question in the Decidim::Forms component.
Constant Summary collapse
- QUESTION_TYPES =
%w(short_answer long_answer single_option multiple_option sorting files matrix_single matrix_multiple).freeze
- SEPARATOR_TYPE =
"separator"
- TITLE_AND_DESCRIPTION_TYPE =
"title_and_description"
- TYPES =
(QUESTION_TYPES + [SEPARATOR_TYPE, TITLE_AND_DESCRIPTION_TYPE]).freeze
Instance Method Summary collapse
- #answers_count ⇒ Object
- #has_attachments? ⇒ Boolean
- #mandatory_body? ⇒ Boolean
- #mandatory_choices? ⇒ Boolean
- #matrix? ⇒ Boolean
- #multiple_choice? ⇒ Boolean
- #number_of_options ⇒ Object
- #separator? ⇒ Boolean
- #title_and_description? ⇒ Boolean
- #translated_body ⇒ Object
Instance Method Details
#answers_count ⇒ Object
97 98 99 |
# File 'app/models/decidim/forms/question.rb', line 97 def answers_count questionnaire.answers.where(question: self).count end |
#has_attachments? ⇒ Boolean
93 94 95 |
# File 'app/models/decidim/forms/question.rb', line 93 def question_type.to_s == "files" end |
#mandatory_body? ⇒ Boolean
69 70 71 |
# File 'app/models/decidim/forms/question.rb', line 69 def mandatory_body? mandatory? && !multiple_choice? && ! end |
#mandatory_choices? ⇒ Boolean
73 74 75 |
# File 'app/models/decidim/forms/question.rb', line 73 def mandatory_choices? mandatory? && multiple_choice? && ! end |
#matrix? ⇒ Boolean
61 62 63 |
# File 'app/models/decidim/forms/question.rb', line 61 def matrix? %w(matrix_single matrix_multiple).include?(question_type) end |
#multiple_choice? ⇒ Boolean
65 66 67 |
# File 'app/models/decidim/forms/question.rb', line 65 def multiple_choice? %w(single_option multiple_option sorting matrix_single matrix_multiple).include?(question_type) end |
#number_of_options ⇒ Object
77 78 79 |
# File 'app/models/decidim/forms/question.rb', line 77 def .size end |
#separator? ⇒ Boolean
85 86 87 |
# File 'app/models/decidim/forms/question.rb', line 85 def separator? question_type.to_s == SEPARATOR_TYPE end |
#title_and_description? ⇒ Boolean
89 90 91 |
# File 'app/models/decidim/forms/question.rb', line 89 def title_and_description? question_type.to_s == TITLE_AND_DESCRIPTION_TYPE end |
#translated_body ⇒ Object
81 82 83 |
# File 'app/models/decidim/forms/question.rb', line 81 def translated_body Decidim::Forms::QuestionPresenter.new(self).translated_body end |