Class: Basketball::Season::Division

Inherits:
Entity
  • Object
show all
Includes:
HasTeams
Defined in:
lib/basketball/season/division.rb

Overview

A collection of teams and players.

Instance Attribute Summary collapse

Attributes inherited from Entity

#id

Instance Method Summary collapse

Methods included from HasTeams

#team?

Methods included from HasPlayers

#player?

Methods inherited from Entity

#<=>, #==, #comparable_id, #hash

Constructor Details

#initialize(id:, name: '', teams: []) ⇒ Division

Returns a new instance of Division.



11
12
13
14
15
16
17
18
19
20
# File 'lib/basketball/season/division.rb', line 11

def initialize(id:, name: '', teams: [])
  super(id)

  @teams = []
  @name  = name.to_s

  teams.each { |t| register_team!(t) }

  freeze
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/basketball/season/division.rb', line 9

def name
  @name
end

#teamsObject (readonly)

Returns the value of attribute teams.



9
10
11
# File 'lib/basketball/season/division.rb', line 9

def teams
  @teams
end

Instance Method Details

#playersObject



26
27
28
# File 'lib/basketball/season/division.rb', line 26

def players
  teams.flat_map(&:players)
end

#to_sObject



22
23
24
# File 'lib/basketball/season/division.rb', line 22

def to_s
  (["[#{super}] #{name}"] + teams.map(&:to_s)).join("\n")
end