Right now, I have the following:
- A
win_streak
column on theUser
table. - This method in
game.rb
I'm interpreting win_streak
as follows:
- The number if the number games in the streak
- The value (positive or negative) specifies whether those games were wins (positive) or losses (negative)
game.rb:
def adjust_streak
u = self.user
case self.result
when 'Win'
u.win_streak > 0 ? u.win_streak += 1 : u.win_streak = 1
when 'Loss'
u.win_streak > 0 ? u.win_streak = -1 : u.win_streak -= 1
end
u.save
end
I'm looking for a cleaner, and more succinct way to do this (e.g. keep track of win/loss streaks).