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