Sha256: 3b9573ea07749d5f804539479ec5fd17d4eed3f14b97cca607e3c83329d2d77b

Contents?: true

Size: 1.4 KB

Versions: 15

Compression:

Stored size: 1.4 KB

Contents

module Sportradar
  module Api
    class Nfl::Hierarchy < Data
      attr_accessor :response, :id, :name, :alias, :divisions, :conferences, :teams

      def initialize(data)
        @response = data
        @id = data["id"]
        @name = data["name"]
        @alias = data["alias"]
        set_conferences
        set_divisions
        set_teams
      end

      private

      def set_conferences
        if response["conference"]
          if response["conference"].is_a?(Array)
            @conferences = response["conference"].map {|conference| Sportradar::Api::Nfl::Conference.new conference }
          elsif response["conference"].is_a?(Hash)
            @conferences = [ Sportradar::Api::Nfl::Conference.new(response["conference"]) ]
          end
        end
      end

      def set_divisions
        if conferences&.all? { |conference| conference.divisions }
          @divisions = conferences.flat_map(&:divisions)
        elsif response["division"]
          if response["division"].is_a?(Array)
            @divisions = response["division"].map {|division| Sportradar::Api::Nfl::Division.new division }
          elsif response["division"].is_a?(Hash)
            @divisions = [ Sportradar::Api::Nfl::Division.new(response["division"]) ]
          end
        end
      end

      def set_teams
        @teams = @divisions.flat_map(&:teams) if divisions&.all? {|division| division.teams }
      end

    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
sportradar-api-0.1.38 lib/sportradar/api/nfl/hierarchy.rb
sportradar-api-0.1.37 lib/sportradar/api/nfl/hierarchy.rb
sportradar-api-0.1.36 lib/sportradar/api/nfl/hierarchy.rb
sportradar-api-0.1.35 lib/sportradar/api/nfl/hierarchy.rb
sportradar-api-0.1.34 lib/sportradar/api/nfl/hierarchy.rb
sportradar-api-0.1.33 lib/sportradar/api/nfl/hierarchy.rb
sportradar-api-0.1.32 lib/sportradar/api/nfl/hierarchy.rb
sportradar-api-0.1.31 lib/sportradar/api/nfl/hierarchy.rb
sportradar-api-0.1.30 lib/sportradar/api/nfl/hierarchy.rb
sportradar-api-0.1.29 lib/sportradar/api/nfl/hierarchy.rb
sportradar-api-0.1.28 lib/sportradar/api/nfl/hierarchy.rb
sportradar-api-0.1.27 lib/sportradar/api/nfl/hierarchy.rb
sportradar-api-0.1.26 lib/sportradar/api/nfl/hierarchy.rb
sportradar-api-0.1.25 lib/sportradar/api/nfl/hierarchy.rb
sportradar-api-0.1.24 lib/sportradar/api/nfl/hierarchy.rb