Class: Honor::Point
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Honor::Point
- Defined in:
- lib/honor/point.rb
Class Method Summary collapse
- .give_to(user_id, number_of_points, message = "Manually granted through 'add_points'", category = 'default') ⇒ Object
- .take_from(user_id, number_of_points, message = "Manually granted through 'add_points'", category = 'default') ⇒ Object
- .user_points_this_month(user_id) ⇒ Object
- .user_points_this_week(user_id) ⇒ Object
- .user_points_this_year(user_id) ⇒ Object
- .user_points_today(user_id) ⇒ Object
- .user_points_total(user_id) ⇒ Object
Class Method Details
.give_to(user_id, number_of_points, message = "Manually granted through 'add_points'", category = 'default') ⇒ Object
7 8 9 |
# File 'lib/honor/point.rb', line 7 def give_to(user_id, number_of_points, = "Manually granted through 'add_points'", category = 'default') create!({user_id: user_id, value: number_of_points, message: , category: category}) end |
.take_from(user_id, number_of_points, message = "Manually granted through 'add_points'", category = 'default') ⇒ Object
11 12 13 |
# File 'lib/honor/point.rb', line 11 def take_from(user_id, number_of_points, = "Manually granted through 'add_points'", category = 'default') give_to user_id, -number_of_points, , category end |
.user_points_this_month(user_id) ⇒ Object
27 28 29 |
# File 'lib/honor/point.rb', line 27 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) end |
.user_points_this_week(user_id) ⇒ Object
23 24 25 |
# File 'lib/honor/point.rb', line 23 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) end |
.user_points_this_year(user_id) ⇒ Object
31 32 33 |
# File 'lib/honor/point.rb', line 31 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) end |
.user_points_today(user_id) ⇒ Object
19 20 21 |
# File 'lib/honor/point.rb', line 19 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) end |
.user_points_total(user_id) ⇒ Object
15 16 17 |
# File 'lib/honor/point.rb', line 15 def user_points_total(user_id) where(user_id: user_id).sum(:value) end |