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.19.7 app/models/wai_assessment.rb
think_feel_do_engine-3.19.6 app/models/wai_assessment.rb
think_feel_do_engine-3.19.5 app/models/wai_assessment.rb
think_feel_do_engine-3.19.4 app/models/wai_assessment.rb
think_feel_do_engine-3.19.3 app/models/wai_assessment.rb
think_feel_do_engine-3.19.2 app/models/wai_assessment.rb
think_feel_do_engine-3.19.1 app/models/wai_assessment.rb
think_feel_do_engine-3.19.0 app/models/wai_assessment.rb
think_feel_do_engine-3.18.0 app/models/wai_assessment.rb
think_feel_do_engine-3.17.2 app/models/wai_assessment.rb
think_feel_do_engine-3.17.1 app/models/wai_assessment.rb
think_feel_do_engine-3.17.0 app/models/wai_assessment.rb
think_feel_do_engine-3.16.3 app/models/wai_assessment.rb
think_feel_do_engine-3.16.2 app/models/wai_assessment.rb
think_feel_do_engine-3.16.1 app/models/wai_assessment.rb
think_feel_do_engine-3.15.7 app/models/wai_assessment.rb
think_feel_do_engine-3.16.0 app/models/wai_assessment.rb
think_feel_do_engine-3.15.6 app/models/wai_assessment.rb
think_feel_do_engine-3.15.5 app/models/wai_assessment.rb
think_feel_do_engine-3.15.4 app/models/wai_assessment.rb