Class: CrashingTheDance::RpiCalculator::OpponentGame

Inherits:
Object
  • Object
show all
Defined in:
lib/crashing_the_dance/rpi_calculator/opponent_game.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(game, team) ⇒ OpponentGame

Returns a new instance of OpponentGame.



5
6
7
8
9
# File 'lib/crashing_the_dance/rpi_calculator/opponent_game.rb', line 5

def initialize(game, team)
  @game = game
  @team = team
  scores
end

Instance Attribute Details

#gameObject (readonly)

Returns the value of attribute game.



4
5
6
# File 'lib/crashing_the_dance/rpi_calculator/opponent_game.rb', line 4

def game
  @game
end

#opponentObject (readonly)

Returns the value of attribute opponent.



4
5
6
# File 'lib/crashing_the_dance/rpi_calculator/opponent_game.rb', line 4

def opponent
  @opponent
end

#opponent_scoreObject (readonly)

Returns the value of attribute opponent_score.



4
5
6
# File 'lib/crashing_the_dance/rpi_calculator/opponent_game.rb', line 4

def opponent_score
  @opponent_score
end

#scoreObject (readonly)

Returns the value of attribute score.



4
5
6
# File 'lib/crashing_the_dance/rpi_calculator/opponent_game.rb', line 4

def score
  @score
end

#teamObject (readonly)

Returns the value of attribute team.



4
5
6
# File 'lib/crashing_the_dance/rpi_calculator/opponent_game.rb', line 4

def team
  @team
end

Instance Method Details

#home?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/crashing_the_dance/rpi_calculator/opponent_game.rb', line 49

def home?
  @which_team == :home && !neutral?
end

#loss?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/crashing_the_dance/rpi_calculator/opponent_game.rb', line 19

def loss?
  score < opponent_score
end

#lossesObject



27
28
29
# File 'lib/crashing_the_dance/rpi_calculator/opponent_game.rb', line 27

def losses
  loss? ? 1 : 0
end

#neutral?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/crashing_the_dance/rpi_calculator/opponent_game.rb', line 11

def neutral?
  game.neutral?
end

#rpi_lossesObject



40
41
42
43
44
45
46
47
# File 'lib/crashing_the_dance/rpi_calculator/opponent_game.rb', line 40

def rpi_losses
  case
  when win? then     0.0
  when visitor? then 0.6
  when home? then    1.4
  else               1.0
  end
end

#rpi_winsObject



31
32
33
34
35
36
37
38
# File 'lib/crashing_the_dance/rpi_calculator/opponent_game.rb', line 31

def rpi_wins
  case
  when loss? then    0.0
  when home? then    0.6
  when visitor? then 1.4
  else               1.0
  end
end

#visitor?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/crashing_the_dance/rpi_calculator/opponent_game.rb', line 53

def visitor?
  @which_team == :visitor && !neutral?
end

#win?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/crashing_the_dance/rpi_calculator/opponent_game.rb', line 15

def win?
  score > opponent_score
end

#winsObject



23
24
25
# File 'lib/crashing_the_dance/rpi_calculator/opponent_game.rb', line 23

def wins
  win? ? 1 : 0
end