Created
July 1, 2018 00:39
-
-
Save jarednorman/96bf696b05b061cf03e647a04423ac9f to your computer and use it in GitHub Desktop.
The Elo handling from PorkChop, without the other stuff in the model. (Original source: https://github.com/PorkChopClub/porkchop/blob/master/app/models/player.rb)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player < ActiveRecord::Base | |
BASE_ELO = 1000 | |
has_many :elo_ratings | |
after_save :record_rating | |
attr_writer :elo | |
def elo | |
elo_ratings.most_recent_rating || BASE_ELO | |
end | |
def elo_on(date) | |
elo_ratings.rating_on(date) || BASE_ELO | |
end | |
private | |
def record_rating | |
return unless @elo | |
elo_ratings.create(rating: @elo) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment