Class: Glicko2::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/glicko2/player.rb

Overview

Player maps a seed object with a Glicko2 rating.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rating, obj) ⇒ Player

Returns a new instance of Player.



16
17
18
19
# File 'lib/glicko2/player.rb', line 16

def initialize(rating, obj)
  @rating = rating
  @obj = obj
end

Instance Attribute Details

#objObject (readonly)

Returns the value of attribute obj.



4
5
6
# File 'lib/glicko2/player.rb', line 4

def obj
  @obj
end

#ratingObject (readonly)

Returns the value of attribute rating.



4
5
6
# File 'lib/glicko2/player.rb', line 4

def rating
  @rating
end

Class Method Details

.from_obj(obj) ⇒ Player

Create a Glicko2::Player from a seed object, converting from Glicko ratings to Glicko2.

Parameters:

Returns:

  • (Player)

    constructed instance.



11
12
13
14
# File 'lib/glicko2/player.rb', line 11

def self.from_obj(obj)
  rating = Rating.from_glicko_rating(obj.rating, obj.rating_deviation, obj.volatility)
  new(rating, obj)
end

Instance Method Details

#meanObject



29
30
31
# File 'lib/glicko2/player.rb', line 29

def mean
  rating.mean
end

#sdObject



33
34
35
# File 'lib/glicko2/player.rb', line 33

def sd
  rating.sd
end

#to_sObject



41
42
43
# File 'lib/glicko2/player.rb', line 41

def to_s
  "#<Player rating=#{rating}, obj=#{obj}>"
end

#update_objObject

Update seed object with this player’s values



22
23
24
25
26
27
# File 'lib/glicko2/player.rb', line 22

def update_obj
  mean, sd = rating.to_glicko_rating
  @obj.rating = mean
  @obj.rating_deviation = sd
  @obj.volatility = volatility
end

#volatilityObject



37
38
39
# File 'lib/glicko2/player.rb', line 37

def volatility
  rating.volatility
end