Sha256: 670638bdfc38897d367e1b854d8cee9146042374634e40260e03a0cc12e01f92

Contents?: true

Size: 939 Bytes

Versions: 7

Compression:

Stored size: 939 Bytes

Contents

# frozen_string_literal: true

module Basketball
  module Org
    # A collection of divisions, teams, and players.
    class Conference < Entity
      include HasDivisions

      attr_reader :divisions

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

        @divisions = []

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

        freeze
      end

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

      def teams
        divisions.flat_map(&:teams)
      end

      def players
        divisions.flat_map(&:players)
      end

      private

      def register_division!(division)
        raise ArgumentError, 'division is required' unless division
        raise DivisionAlreadyRegisteredError, "#{division} already registered" if division?(division)

        assert_teams_are_not_already_registered(division.teams)

        divisions << division

        self
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
basketball-0.0.17 lib/basketball/org/conference.rb
basketball-0.0.16 lib/basketball/org/conference.rb
basketball-0.0.15 lib/basketball/org/conference.rb
basketball-0.0.14 lib/basketball/org/conference.rb
basketball-0.0.13 lib/basketball/org/conference.rb
basketball-0.0.12 lib/basketball/org/conference.rb
basketball-0.0.11 lib/basketball/org/conference.rb