Sha256: 6987f0fae0966283b5b3a0429e658809e63b8e970718ba064025a27c6c3efba9

Contents?: true

Size: 766 Bytes

Versions: 11

Compression:

Stored size: 766 Bytes

Contents

# frozen_string_literal: true
# Participants rate their emotions a name and intensity
class Emotion < ActiveRecord::Base
  belongs_to :creator, class_name: "Participant"
  has_many :emotional_ratings, dependent: :destroy

  validates :creator, presence: true
  validates :name, presence: true
  validates :name, uniqueness: { scope: :creator_id }
  validates :name, length: { maximum: 255 }

  before_validation :normalize_name

  def self.associate(participant, name)
    find_or_create_by(
      creator_id: participant.id,
      name: normalized_name(name)
    )
  end

  def self.normalized_name(n)
    n.strip.downcase
  end

  private

  def normalize_name
    return unless name.respond_to?(:strip)

    self.name = self.class.normalized_name(name)
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
think_feel_do_engine-3.22.9 app/models/emotion.rb
think_feel_do_engine-3.22.8 app/models/emotion.rb
think_feel_do_engine-3.22.7 app/models/emotion.rb
think_feel_do_engine-3.22.6 app/models/emotion.rb
think_feel_do_engine-3.22.5 app/models/emotion.rb
think_feel_do_engine-3.22.4 app/models/emotion.rb
think_feel_do_engine-3.22.2 app/models/emotion.rb
think_feel_do_engine-3.22.1 app/models/emotion.rb
think_feel_do_engine-3.22.0 app/models/emotion.rb
think_feel_do_engine-3.21.2 app/models/emotion.rb
think_feel_do_engine-3.21.1 app/models/emotion.rb