Class: Basketball::Season::Conference

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

Overview

A collection of divisions, teams, and players.

Instance Attribute Summary collapse

Attributes inherited from Entity

#id

Instance Method Summary collapse

Methods included from HasDivisions

#division?

Methods included from HasTeams

#team?

Methods included from HasPlayers

#player?

Methods inherited from Entity

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

Constructor Details

#initialize(id:, name: '', divisions: []) ⇒ Conference

Returns a new instance of Conference.



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

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

  @divisions = []
  @name      = name.to_s

  divisions.each { |d| register_division!(d) }

  freeze
end

Instance Attribute Details

#divisionsObject (readonly)

Returns the value of attribute divisions.



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

def divisions
  @divisions
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#playersObject



30
31
32
# File 'lib/basketball/season/conference.rb', line 30

def players
  divisions.flat_map(&:players)
end

#teamsObject



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

def teams
  divisions.flat_map(&:teams)
end

#to_sObject



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

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