Class: Basketball::Season::Conference
- Includes:
- HasDivisions
- Defined in:
- lib/basketball/season/conference.rb
Overview
A collection of divisions, teams, and players.
Instance Attribute Summary collapse
-
#divisions ⇒ Object
readonly
Returns the value of attribute divisions.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from Entity
Instance Method Summary collapse
-
#initialize(id:, name: '', divisions: []) ⇒ Conference
constructor
A new instance of Conference.
- #players ⇒ Object
- #teams ⇒ Object
- #to_s ⇒ Object
Methods included from HasDivisions
Methods included from HasTeams
Methods included from HasPlayers
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
#divisions ⇒ Object (readonly)
Returns the value of attribute divisions.
9 10 11 |
# File 'lib/basketball/season/conference.rb', line 9 def divisions @divisions end |
#name ⇒ Object (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
#players ⇒ Object
30 31 32 |
# File 'lib/basketball/season/conference.rb', line 30 def players divisions.flat_map(&:players) end |
#teams ⇒ Object
26 27 28 |
# File 'lib/basketball/season/conference.rb', line 26 def teams divisions.flat_map(&:teams) end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/basketball/season/conference.rb', line 22 def to_s (["[#{super}] #{name}"] + divisions.map(&:to_s)).join("\n") end |