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