Sha256: 69089a09ff10d10b63f7e4f6bf2b85b4e30eb6321498f621ae59f1a8fdf6baf6

Contents?: true

Size: 865 Bytes

Versions: 53

Compression:

Stored size: 865 Bytes

Contents

# Collected responses from one Participant WAI assessment session.
class WaiAssessment < ActiveRecord::Base
  MIN_QUESTION_SCORE = 1
  MAX_QUESTION_SCORE = 5
  QUESTION_COUNT = 12
  QUESTION_ATTRIBUTES = :q1, :q2, :q3, :q4, :q5, :q6, :q7, :q8, :q9, :q10, :q11,
                        :q12

  belongs_to :participant

  validates :participant, :release_date, presence: true
  validates :release_date, uniqueness: { scope: :participant_id }
  validate :scores_valid

  private

  def scores_valid
    return unless remove_nils.length > 0

    if remove_nils.min < MIN_QUESTION_SCORE ||
       remove_nils.max > MAX_QUESTION_SCORE
      errors.add(:base, "scores must be between #{ MIN_QUESTION_SCORE } " \
                        "and #{ MAX_QUESTION_SCORE } inclusive")
    end
  end

  def remove_nils
    QUESTION_ATTRIBUTES.map { |a| self[a] }.compact
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
think_feel_do_engine-3.12.5 app/models/wai_assessment.rb
think_feel_do_engine-3.12.4 app/models/wai_assessment.rb
think_feel_do_engine-3.12.3 app/models/wai_assessment.rb
think_feel_do_engine-3.12.2 app/models/wai_assessment.rb
think_feel_do_engine-3.12.1 app/models/wai_assessment.rb
think_feel_do_engine-3.12.0 app/models/wai_assessment.rb
think_feel_do_engine-3.11.3 app/models/wai_assessment.rb
think_feel_do_engine-3.11.0 app/models/wai_assessment.rb
think_feel_do_engine-3.10.10 app/models/wai_assessment.rb
think_feel_do_engine-3.10.9 app/models/wai_assessment.rb
think_feel_do_engine-3.10.8 app/models/wai_assessment.rb
think_feel_do_engine-3.10.7 app/models/wai_assessment.rb
think_feel_do_engine-3.10.6 app/models/wai_assessment.rb