Module: EloRankable::HasEloRanking::InstanceMethods

Defined in:
lib/elo_rankable/has_elo_ranking.rb

Instance Method Summary collapse

Instance Method Details

#beat!(other_player) ⇒ Object Also known as: elo_beat!

Domain-style DSL methods



34
35
36
37
# File 'lib/elo_rankable/has_elo_ranking.rb', line 34

def beat!(other_player)
  validate_opponent!(other_player)
  EloRankable::Calculator.update_ratings_for_win(self, other_player)
end

#draw_with!(other_player) ⇒ Object Also known as: elo_draw_with!



44
45
46
47
# File 'lib/elo_rankable/has_elo_ranking.rb', line 44

def draw_with!(other_player)
  validate_opponent!(other_player)
  EloRankable::Calculator.update_ratings_for_draw(self, other_player)
end

#elo_rankingObject



18
19
20
21
22
23
# File 'lib/elo_rankable/has_elo_ranking.rb', line 18

def elo_ranking
  super || create_elo_ranking!(
    rating: EloRankable.config.base_rating,
    games_played: 0
  )
end

#elo_ratingObject



25
26
27
# File 'lib/elo_rankable/has_elo_ranking.rb', line 25

def elo_rating
  elo_ranking.rating
end

#games_playedObject



29
30
31
# File 'lib/elo_rankable/has_elo_ranking.rb', line 29

def games_played
  elo_ranking.games_played
end

#lost_to!(other_player) ⇒ Object Also known as: elo_lost_to!



39
40
41
42
# File 'lib/elo_rankable/has_elo_ranking.rb', line 39

def lost_to!(other_player)
  validate_opponent!(other_player)
  EloRankable::Calculator.update_ratings_for_win(other_player, self)
end