Class: KillerQueenSceneScoring::Scene

Inherits:
Object
  • Object
show all
Defined in:
lib/killer_queen_scene_scoring/scene.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, player_scores) ⇒ Scene

‘name` is the name of the scene. `player_scores` is an array that holds the points that were awarded to each player in the scene.



10
11
12
13
14
# File 'lib/killer_queen_scene_scoring/scene.rb', line 10

def initialize(name, player_scores)
    @name = name
    @score = player_scores.sum
    @num_players = player_scores.size
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/killer_queen_scene_scoring/scene.rb', line 6

def name
  @name
end

#num_playersObject

Returns the value of attribute num_players.



6
7
8
# File 'lib/killer_queen_scene_scoring/scene.rb', line 6

def num_players
  @num_players
end

#scoreObject

Returns the value of attribute score.



6
7
8
# File 'lib/killer_queen_scene_scoring/scene.rb', line 6

def score
  @score
end

Instance Method Details

#<=>(rhs) ⇒ Object



20
21
22
23
# File 'lib/killer_queen_scene_scoring/scene.rb', line 20

def <=>(rhs)
    # Sort by score in descending order so the largest scores come first.
    @score != rhs.score ? rhs.score <=> @score : @name <=> rhs.name
end

#to_sObject



16
17
18
# File 'lib/killer_queen_scene_scoring/scene.rb', line 16

def to_s
    "#{@name}: #{@score} points from #{@num_players} players"
end