Sha256: 2e180700d8dd377a9070ff16a3958e60ca7e5e1952d390495a2b84f68e6e29c2

Contents?: true

Size: 811 Bytes

Versions: 13

Compression:

Stored size: 811 Bytes

Contents

# frozen_string_literal: true
# Participants rate their mood
class Mood < ActiveRecord::Base
  belongs_to :participant
  validates :participant, presence: true
  validates :rating, presence: true, inclusion: { in: 0..10 }

  scope :for_day, lambda { |datetime|
    where(
      arel_table[:created_at].gteq(datetime.beginning_of_day)
      .and(arel_table[:created_at].lteq(datetime.end_of_day))
    )
  }

  def rating_value
    Values::Mood.from_rating(rating).to_s
  end

  scope :last_seven_days, lambda {
    where(
      arel_table[:created_at]
        .gteq(Time.current.advance(days: -7).beginning_of_day)
    )
  }

  scope :for_day, lambda { |time|
    where(
      arel_table[:created_at]
        .gteq(time.beginning_of_day)
        .and(arel_table[:created_at].lteq(time.end_of_day))
    )
  }
end

Version data entries

13 entries across 13 versions & 1 rubygems

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