Module: TreasureHunt::Achievement::InstanceMethods
- Defined in:
- lib/treasure_hunt/achievement.rb
Instance Method Summary collapse
- #fill_points ⇒ Object
- #find_all_recently_achieved ⇒ Object
- #find_all_similar ⇒ Object
- #find_all_similar_and_younger ⇒ Object
-
#reward_cannot_be_achieved_above_limits ⇒ Object
TODO refactoring to Validator.
Instance Method Details
#fill_points ⇒ Object
28 29 30 |
# File 'lib/treasure_hunt/achievement.rb', line 28 def fill_points self.points = self.reward.points unless self.points end |
#find_all_recently_achieved ⇒ Object
54 55 56 57 58 |
# File 'lib/treasure_hunt/achievement.rb', line 54 def find_all_recently_achieved limit = self.reward.limit rescue 1.0/0 # Yep, that's Infinity find_all_similar_and_younger.limit(limit) end |
#find_all_similar ⇒ Object
41 42 43 44 45 46 |
# File 'lib/treasure_hunt/achievement.rb', line 41 def find_all_similar ret = self.class.where(:user_id => self.user_id, :reward_id => self.reward_id).order('updated_at DESC') ret = ret.where('id != ?', self.id) if self.id ret end |
#find_all_similar_and_younger ⇒ Object
48 49 50 51 52 |
# File 'lib/treasure_hunt/achievement.rb', line 48 def find_all_similar_and_younger age = Time.now - self.reward.every rescue 0 find_all_similar.where('updated_at > ?', age) end |
#reward_cannot_be_achieved_above_limits ⇒ Object
TODO refactoring to Validator
33 34 35 36 37 38 39 |
# File 'lib/treasure_hunt/achievement.rb', line 33 def reward_cannot_be_achieved_above_limits limit = self.reward.limit rescue 1.0/0 if self.find_all_similar_and_younger.size >= limit errors.add(:reward, "can't achieve reward at current time") end end |