diff options
Diffstat (limited to 'app/models/state.rb')
-rw-r--r-- | app/models/state.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/app/models/state.rb b/app/models/state.rb new file mode 100644 index 0000000..27c8741 --- /dev/null +++ b/app/models/state.rb @@ -0,0 +1,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 |