mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-04-15 12:07:43 +00:00
28 lines
640 B
Ruby
28 lines
640 B
Ruby
class Habit < ActiveRecord::Base
|
|
ALWAYS = 1
|
|
DAILY = 2
|
|
ONE_TIME = 3
|
|
|
|
belongs_to :user
|
|
|
|
default_scope :order => 'position ASC'
|
|
|
|
# TODO set cron for this
|
|
def self.clear_done
|
|
Habit.where(:habit_type => Habit::DAILY).collect do |h|
|
|
h.vote('down') unless h.done
|
|
h.done = false
|
|
h.save
|
|
end
|
|
end
|
|
|
|
def vote(direction)
|
|
next_vote = 1 #TODO return log or linear based on current score
|
|
next_vote *= -1 if(direction=='down')
|
|
self.score += next_vote
|
|
if(self.habit_type==Habit::DAILY)
|
|
self.done = true if direction=='up'
|
|
self.done = false if direction=='down'
|
|
end
|
|
end
|
|
end
|