Class: Decidim::Forms::Question

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

Instance Method Details

#answers_countObject



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

Returns:

  • (Boolean)


93
94
95
# File 'app/models/decidim/forms/question.rb', line 93

def has_attachments?
  question_type.to_s == "files"
end

#mandatory_body?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/models/decidim/forms/question.rb', line 69

def mandatory_body?
  mandatory? && !multiple_choice? && !has_attachments?
end

#mandatory_choices?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'app/models/decidim/forms/question.rb', line 73

def mandatory_choices?
  mandatory? && multiple_choice? && !has_attachments?
end

#matrix?Boolean

Returns:

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

Returns:

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



77
78
79
# File 'app/models/decidim/forms/question.rb', line 77

def number_of_options
  answer_options.size
end

#separator?Boolean

Returns:

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

Returns:

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



81
82
83
# File 'app/models/decidim/forms/question.rb', line 81

def translated_body
  Decidim::Forms::QuestionPresenter.new(self).translated_body
end