moodtracker/mood.rb
Christophe Robillard 4caf937019 pimp view
wip
2024-10-07 21:49:51 +02:00

28 lines
743 B
Ruby

class Mood < ActiveRecord::Base
default_scope { order(:recorded_at) }
validates_presence_of :mode
validates_presence_of :recorded_at
def self.log
return if Mood.count < 1
first_mood = Mood.first.recorded_at.to_date
first_monday = first_mood - (first_mood.wday - 1)
current_date = first_monday
current_mode = nil
log_mood = []
Mood.all.each do |mood|
while current_date < mood.recorded_at.to_date do
log_mood << [ current_date.to_s, current_mode ]
current_date += 1
end
current_mode = mood.mode
end
while current_date <= Date.today do
log_mood << [ current_date.to_s, current_mode ]
current_date += 1
end
log_mood.each_slice(7).to_a
end
end