Seems like there should be a good way via MP to DRY this up:
class Dashboard
def self.num_registrations_past_day
return User.recent_registrations(24.hours.ago).count
end
def self.num_registrations_past_three_days
return User.recent_registrations(3.days.ago).count
end
def self.num_registrations_past_seven_days
return User.recent_registrations(7.days.ago).count
end
def self.num_registrations_past_month
return User.recent_registrations(30.days.ago).count
end
def self.avg_registrations_past_three_days
return (self.num_registrations_past_three_days / 3.to_f)
end
def self.avg_registrations_past_seven_days
return (self.num_registrations_past_seven_days / 7.to_f)
end
def self.avg_registrations_past_month
return (self.num_registrations_past_month / 30.to_f)
end
def self.total_registered_users
return User.count
end
def self.total_activated_users
return User.total_activated
end
end
I would just have the length of time passed in as an argument:
See, it’s still very readable:
For fun, here is the metaprogramming way: