Class: IttfPoints::Player
- Inherits:
-
Object
- Object
- IttfPoints::Player
- Defined in:
- lib/ittf_points/player.rb
Instance Attribute Summary collapse
-
#gained_rating_points ⇒ Object
readonly
Returns the value of attribute gained_rating_points.
-
#lost_rating_points ⇒ Object
readonly
Returns the value of attribute lost_rating_points.
-
#points_difference ⇒ Object
readonly
Returns the value of attribute points_difference.
-
#weight ⇒ Object
Returns the value of attribute weight.
Instance Method Summary collapse
-
#initialize(rating_points: nil, weight: :r2) ⇒ Player
constructor
A new instance of Player.
- #lose(*rating_points) ⇒ Object
- #new_added_rating_points ⇒ Object
- #new_rating_points ⇒ Object
- #weighting(weight) ⇒ Object
- #win(*rating_points) ⇒ Object
Constructor Details
#initialize(rating_points: nil, weight: :r2) ⇒ Player
Returns a new instance of Player.
6 7 8 9 |
# File 'lib/ittf_points/player.rb', line 6 def initialize(rating_points: nil, weight: :r2) @rating_points = .to_i @weight = weight.downcase.to_sym end |
Instance Attribute Details
#gained_rating_points ⇒ Object (readonly)
Returns the value of attribute gained_rating_points.
3 4 5 |
# File 'lib/ittf_points/player.rb', line 3 def @gained_rating_points end |
#lost_rating_points ⇒ Object (readonly)
Returns the value of attribute lost_rating_points.
3 4 5 |
# File 'lib/ittf_points/player.rb', line 3 def @lost_rating_points end |
#points_difference ⇒ Object (readonly)
Returns the value of attribute points_difference.
3 4 5 |
# File 'lib/ittf_points/player.rb', line 3 def points_difference @points_difference end |
#weight ⇒ Object
Returns the value of attribute weight.
4 5 6 |
# File 'lib/ittf_points/player.rb', line 4 def weight @weight end |
Instance Method Details
#lose(*rating_points) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/ittf_points/player.rb', line 20 def lose(*) @winner_flag = false .flatten.each do |points| @opponent_rating_pts = points.to_i expected_or_unexpected(winner: @opponent_rating_pts, loser: @rating_points) end self end |
#new_added_rating_points ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ittf_points/player.rb', line 29 def if defined?(@gained_rating_points) gained = @gained_rating_points.inject(:+) else gained = 0 end if defined?(@lost_rating_points) lost = @lost_rating_points.inject(:+) else lost = 0 end gained - lost end |
#new_rating_points ⇒ Object
44 45 46 |
# File 'lib/ittf_points/player.rb', line 44 def + @rating_points end |
#weighting(weight) ⇒ Object
48 49 50 51 |
# File 'lib/ittf_points/player.rb', line 48 def weighting(weight) @weight = weight.downcase.to_sym self end |
#win(*rating_points) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/ittf_points/player.rb', line 11 def win(*) @winner_flag = true .flatten.each do |points| @opponent_rating_pts = points.to_i expected_or_unexpected(winner: @rating_points, loser: @opponent_rating_pts) end self end |