summaryrefslogtreecommitdiff
path: root/app/models/state.rb
blob: 27c8741aa31ee761b65345cb0d15d15f8dd7e5c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class State < ApplicationRecord
  belongs_to :character
  belongs_to :condition

  after_create :destroy_duplicates

  def expired?
    self.expires_at < Time.now
  end

  def remaining_duration
    (self.expires_at - Time.now).to_i
  end

  def effects
    self.condition.whatnot[:effects]
  end

  private
    def destroy_duplicates
      self.character.states.where(condition: self.condition).where.not(id: self.id).destroy_all
    end
end