lib/honor/point.rb in honor-1.0.3 vs lib/honor/point.rb in honor-2.0.0
- old
+ new
@@ -1,8 +1,7 @@
module Honor
class Point < ActiveRecord::Base
- attr_accessible :category, :message, :user_id, :value
after_save :update_scorecard
class << self
def give_to(user_id, number_of_points, message = "Manually granted through 'add_points'", category = 'default')
@@ -12,40 +11,40 @@
def take_from(user_id, number_of_points, message = "Manually granted through 'add_points'", category = 'default')
give_to user_id, -number_of_points, message, category
end
def user_points_total(user_id)
- where(:user_id => user_id).sum(:value)
+ where(user_id: user_id).sum(:value)
end
def user_points_today(user_id)
- where(:user_id => user_id).where(:created_at => Time.zone.now.beginning_of_day..Time.zone.now.end_of_day).sum(:value)
+ where(user_id: user_id).where(created_at: Time.zone.now.beginning_of_day..Time.zone.now.end_of_day).sum(:value)
end
def user_points_this_week(user_id)
- where(:user_id => user_id).where(:created_at => Time.zone.now.beginning_of_week..Time.zone.now.end_of_week).sum(:value)
+ where(user_id: user_id).where(created_at: Time.zone.now.beginning_of_week..Time.zone.now.end_of_week).sum(:value)
end
def user_points_this_month(user_id)
- where(:user_id => user_id).where(:created_at => Time.zone.now.beginning_of_month..Time.zone.now.end_of_month).sum(:value)
+ where(user_id: user_id).where(created_at: Time.zone.now.beginning_of_month..Time.zone.now.end_of_month).sum(:value)
end
def user_points_this_year(user_id)
- where(:user_id => user_id).where(:created_at => Time.zone.now.beginning_of_year..Time.zone.now.end_of_year).sum(:value)
+ where(user_id: user_id).where(created_at: Time.zone.now.beginning_of_year..Time.zone.now.end_of_year).sum(:value)
end
end
private
def update_scorecard
- scorecard = Honor::Scorecard.find_or_initialize_by_user_id(user_id)
+ scorecard = Honor::Scorecard.find_or_initialize_by user_id: user_id
scorecard.daily = Honor::Point.user_points_today(user_id)
scorecard.weekly = Honor::Point.user_points_this_week(user_id)
scorecard.monthly = Honor::Point.user_points_this_month(user_id)
scorecard.yearly = Honor::Point.user_points_this_year(user_id)
scorecard.lifetime = Honor::Point.user_points_total(user_id)
scorecard.save!
end
end
-end
\ No newline at end of file
+end