Class: Decidim::Meetings::Question
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Meetings::Question
- Includes:
- TranslatableResource
- Defined in:
- decidim-meetings/app/models/decidim/meetings/question.rb
Overview
The data store for a Question in the Decidim::Meetings component.
Constant Summary collapse
- QUESTION_TYPES =
%w(single_option multiple_option).freeze
Instance Method Summary collapse
-
#answered_by?(user) ⇒ Boolean
Public: returns whether the questionnaire is answered by the user or not.
- #answers_count ⇒ Object
- #multiple_choice? ⇒ Boolean
- #number_of_options ⇒ Object
- #translated_body ⇒ Object
Instance Method Details
#answered_by?(user) ⇒ Boolean
Public: returns whether the questionnaire is answered by the user or not.
38 39 40 |
# File 'decidim-meetings/app/models/decidim/meetings/question.rb', line 38 def answered_by?(user) questionnaire.answers.where({ user:, question: self }).any? if questionnaire.questions.present? && user.present? end |
#answers_count ⇒ Object
50 51 52 |
# File 'decidim-meetings/app/models/decidim/meetings/question.rb', line 50 def answers_count questionnaire.answers.where(question: self).count end |
#multiple_choice? ⇒ Boolean
33 34 35 |
# File 'decidim-meetings/app/models/decidim/meetings/question.rb', line 33 def multiple_choice? %w(single_option multiple_option).include?(question_type) end |
#number_of_options ⇒ Object
42 43 44 |
# File 'decidim-meetings/app/models/decidim/meetings/question.rb', line 42 def .size end |
#translated_body ⇒ Object
46 47 48 |
# File 'decidim-meetings/app/models/decidim/meetings/question.rb', line 46 def translated_body Decidim::Forms::QuestionPresenter.new(self).translated_body end |