Class: Decidim::Forms::Question

Inherits:
ApplicationRecord show all
Includes:
TranslatableResource
Defined in:
decidim-forms/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"
TYPES =
(QUESTION_TYPES + [SEPARATOR_TYPE]).freeze

Instance Method Summary collapse

Instance Method Details

#has_attachments?Boolean

Returns:

  • (Boolean)

87
88
89
# File 'decidim-forms/app/models/decidim/forms/question.rb', line 87

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

#mandatory_body?Boolean

Returns:

  • (Boolean)

67
68
69
# File 'decidim-forms/app/models/decidim/forms/question.rb', line 67

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

#mandatory_choices?Boolean

Returns:

  • (Boolean)

71
72
73
# File 'decidim-forms/app/models/decidim/forms/question.rb', line 71

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

#matrix?Boolean

Returns:

  • (Boolean)

59
60
61
# File 'decidim-forms/app/models/decidim/forms/question.rb', line 59

def matrix?
  %w(matrix_single matrix_multiple).include?(question_type)
end

#multiple_choice?Boolean

Returns:

  • (Boolean)

63
64
65
# File 'decidim-forms/app/models/decidim/forms/question.rb', line 63

def multiple_choice?
  %w(single_option multiple_option sorting matrix_single matrix_multiple).include?(question_type)
end

#number_of_optionsObject


75
76
77
# File 'decidim-forms/app/models/decidim/forms/question.rb', line 75

def number_of_options
  answer_options.size
end

#separator?Boolean

Returns:

  • (Boolean)

83
84
85
# File 'decidim-forms/app/models/decidim/forms/question.rb', line 83

def separator?
  question_type.to_s == SEPARATOR_TYPE
end

#translated_bodyObject


79
80
81
# File 'decidim-forms/app/models/decidim/forms/question.rb', line 79

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