2012-02-01 04:09:00 +00:00
|
|
|
class Habit < ActiveRecord::Base
|
2012-02-01 14:50:26 +00:00
|
|
|
ALWAYS = 1
|
|
|
|
|
DAILY = 2
|
|
|
|
|
ONE_TIME = 3
|
|
|
|
|
|
|
|
|
|
belongs_to :user
|
2012-02-01 16:37:29 +00:00
|
|
|
default_scope :order => 'position ASC'
|
2012-02-01 21:57:35 +00:00
|
|
|
acts_as_list
|
2012-02-01 16:37:29 +00:00
|
|
|
|
2012-02-01 15:28:34 +00:00
|
|
|
# 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
|
|
|
|
|
|
2012-02-01 15:03:27 +00:00
|
|
|
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
|
2012-02-01 15:28:34 +00:00
|
|
|
if(self.habit_type==Habit::DAILY)
|
|
|
|
|
self.done = true if direction=='up'
|
|
|
|
|
self.done = false if direction=='down'
|
|
|
|
|
end
|
2012-02-01 14:50:26 +00:00
|
|
|
end
|
2012-02-01 04:09:00 +00:00
|
|
|
end
|