Class: Answer

Inherits:
ApplicationRecord show all
Defined in:
app/models/answer.rb

Overview

Manage Questions answer. Each answer is referred to a Ticket

Relations

Validations

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fileObject

Returns has_attached istance.

Returns:

  • (Object)

    has_attached istance



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/models/answer.rb', line 29

class Answer < ApplicationRecord
  belongs_to :ticket
  belongs_to :question
  has_one_attached :file

  delegate :category, :category_file?, :category_select?, :happening_id, :options, :mandatory?, :title, to: :question, allow_nil: true, prefix: true
  delegate :happening_id, to: :ticket, allow_nil: true, prefix: true
  delegate :attached?, to: :file, prefix: true

  validates :question, uniqueness: { scope: :ticket }
  validates :question_happening_id, comparison: { equal_to: :ticket_happening_id }
  validates :file, presence: true, if: :question_category_file?
  validates :value, absence: true, if: :question_category_file?
  validates :value, presence: true, if: :question_mandatory?, unless: :question_category_file?
  validates :value, inclusion: { in: :options_title }, if: :question_category_select?

  # @return list of valid option for value
  def options_title
    question_options.acceptable.pluck :title
  end
end

#valueString

Returns answer content.

Returns:

  • (String)

    answer content



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/models/answer.rb', line 29

class Answer < ApplicationRecord
  belongs_to :ticket
  belongs_to :question
  has_one_attached :file

  delegate :category, :category_file?, :category_select?, :happening_id, :options, :mandatory?, :title, to: :question, allow_nil: true, prefix: true
  delegate :happening_id, to: :ticket, allow_nil: true, prefix: true
  delegate :attached?, to: :file, prefix: true

  validates :question, uniqueness: { scope: :ticket }
  validates :question_happening_id, comparison: { equal_to: :ticket_happening_id }
  validates :file, presence: true, if: :question_category_file?
  validates :value, absence: true, if: :question_category_file?
  validates :value, presence: true, if: :question_mandatory?, unless: :question_category_file?
  validates :value, inclusion: { in: :options_title }, if: :question_category_select?

  # @return list of valid option for value
  def options_title
    question_options.acceptable.pluck :title
  end
end

Instance Method Details

#categoryString

Returns delegated from Question#category.

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/models/answer.rb', line 29

class Answer < ApplicationRecord
  belongs_to :ticket
  belongs_to :question
  has_one_attached :file

  delegate :category, :category_file?, :category_select?, :happening_id, :options, :mandatory?, :title, to: :question, allow_nil: true, prefix: true
  delegate :happening_id, to: :ticket, allow_nil: true, prefix: true
  delegate :attached?, to: :file, prefix: true

  validates :question, uniqueness: { scope: :ticket }
  validates :question_happening_id, comparison: { equal_to: :ticket_happening_id }
  validates :file, presence: true, if: :question_category_file?
  validates :value, absence: true, if: :question_category_file?
  validates :value, presence: true, if: :question_mandatory?, unless: :question_category_file?
  validates :value, inclusion: { in: :options_title }, if: :question_category_select?

  # @return list of valid option for value
  def options_title
    question_options.acceptable.pluck :title
  end
end

#category_file?String

Returns delegated from Question#category.

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/models/answer.rb', line 29

class Answer < ApplicationRecord
  belongs_to :ticket
  belongs_to :question
  has_one_attached :file

  delegate :category, :category_file?, :category_select?, :happening_id, :options, :mandatory?, :title, to: :question, allow_nil: true, prefix: true
  delegate :happening_id, to: :ticket, allow_nil: true, prefix: true
  delegate :attached?, to: :file, prefix: true

  validates :question, uniqueness: { scope: :ticket }
  validates :question_happening_id, comparison: { equal_to: :ticket_happening_id }
  validates :file, presence: true, if: :question_category_file?
  validates :value, absence: true, if: :question_category_file?
  validates :value, presence: true, if: :question_mandatory?, unless: :question_category_file?
  validates :value, inclusion: { in: :options_title }, if: :question_category_select?

  # @return list of valid option for value
  def options_title
    question_options.acceptable.pluck :title
  end
end

#category_selectString

Returns delegated from Question#category.

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/models/answer.rb', line 29

class Answer < ApplicationRecord
  belongs_to :ticket
  belongs_to :question
  has_one_attached :file

  delegate :category, :category_file?, :category_select?, :happening_id, :options, :mandatory?, :title, to: :question, allow_nil: true, prefix: true
  delegate :happening_id, to: :ticket, allow_nil: true, prefix: true
  delegate :attached?, to: :file, prefix: true

  validates :question, uniqueness: { scope: :ticket }
  validates :question_happening_id, comparison: { equal_to: :ticket_happening_id }
  validates :file, presence: true, if: :question_category_file?
  validates :value, absence: true, if: :question_category_file?
  validates :value, presence: true, if: :question_mandatory?, unless: :question_category_file?
  validates :value, inclusion: { in: :options_title }, if: :question_category_select?

  # @return list of valid option for value
  def options_title
    question_options.acceptable.pluck :title
  end
end

#optionsArray

Returns delegated from Question.

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/models/answer.rb', line 29

class Answer < ApplicationRecord
  belongs_to :ticket
  belongs_to :question
  has_one_attached :file

  delegate :category, :category_file?, :category_select?, :happening_id, :options, :mandatory?, :title, to: :question, allow_nil: true, prefix: true
  delegate :happening_id, to: :ticket, allow_nil: true, prefix: true
  delegate :attached?, to: :file, prefix: true

  validates :question, uniqueness: { scope: :ticket }
  validates :question_happening_id, comparison: { equal_to: :ticket_happening_id }
  validates :file, presence: true, if: :question_category_file?
  validates :value, absence: true, if: :question_category_file?
  validates :value, presence: true, if: :question_mandatory?, unless: :question_category_file?
  validates :value, inclusion: { in: :options_title }, if: :question_category_select?

  # @return list of valid option for value
  def options_title
    question_options.acceptable.pluck :title
  end
end

#options_titleObject

Returns list of valid option for value.

Returns:

  • list of valid option for value



46
47
48
# File 'app/models/answer.rb', line 46

def options_title
  question_options.acceptable.pluck :title
end