Class: Decidim::Meetings::Question

Inherits:
ApplicationRecord show all
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

Instance Method Details

#answered_by?(user) ⇒ Boolean

Public: returns whether the questionnaire is answered by the user or not.

Returns:

  • (Boolean)


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_countObject



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

Returns:

  • (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_optionsObject



42
43
44
# File 'decidim-meetings/app/models/decidim/meetings/question.rb', line 42

def number_of_options
  answer_options.size
end

#translated_bodyObject



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