Sha256: 71d54e42187593dcfbfe10ebc66d663c9d49e004fee37657583ff5ec83fa729d
Contents?: true
Size: 845 Bytes
Versions: 5
Compression:
Stored size: 845 Bytes
Contents
# frozen_string_literal: true module Basketball module Org # A collection of teams and players. class Division < Entity include HasTeams attr_reader :teams, :name def initialize(id:, name: '', teams: []) super(id) @teams = [] @name = name.to_s teams.each { |t| register_team!(t) } freeze end def to_s (["[#{super}] #{name}"] + teams.map(&:to_s)).join("\n") end def players teams.flat_map(&:players) end private def register_team!(team) raise ArgumentError, 'team is required' unless team raise TeamAlreadyRegisteredError, "#{team} already registered" if team?(team) assert_players_are_not_already_signed(team.players) teams << team self end end end end
Version data entries
5 entries across 5 versions & 1 rubygems