Class: IttfPoints::Player

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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 = rating_points.to_i
  @weight = weight.downcase.to_sym
end

Instance Attribute Details

#gained_rating_pointsObject (readonly)

Returns the value of attribute gained_rating_points.



3
4
5
# File 'lib/ittf_points/player.rb', line 3

def gained_rating_points
  @gained_rating_points
end

#lost_rating_pointsObject (readonly)

Returns the value of attribute lost_rating_points.



3
4
5
# File 'lib/ittf_points/player.rb', line 3

def lost_rating_points
  @lost_rating_points
end

#points_differenceObject (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

#weightObject

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(*rating_points)
  @winner_flag = false
  rating_points.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_pointsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ittf_points/player.rb', line 29

def new_added_rating_points
  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_pointsObject



44
45
46
# File 'lib/ittf_points/player.rb', line 44

def new_rating_points
  new_added_rating_points + @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(*rating_points)
  @winner_flag = true
  rating_points.flatten.each do |points|
    @opponent_rating_pts = points.to_i
    expected_or_unexpected(winner: @rating_points, loser: @opponent_rating_pts)
  end
  self
end