Sha256: 2281c5a8bf21360ef08769a8687b123edab4806d6cb96ce35099f6730815554e

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

module ChgkRating
  module Collections
    class Tournaments < Base
      attr_reader :team, :season_id

      def initialize(params = {})
        @team = build_model params[:team]

        @season_id = params[:season_id]
        params.merge!(lazy: true) if @team || @season_id
        super
      end

      def revert_to_hash(key, values)
        [
            key,
            {
                'idteam' => @team.id.to_s,
                'idseason' => key,
                'tournaments' => values.map(&:to_h)
            }
        ]
      end

      private

      def process(_results, params = {})
        super do |result|
          if @team && @season_id.nil?
            ChgkRating::Collections::Tournaments.new(collection: result['tournaments'],
                                                     lazy: true).items
          else
            ChgkRating::Models::Tournament.new result, lazy: params[:lazy]
          end
        end
      end

      def api_path
        path = 'tournaments'
        return path unless @team
        path = "teams/#{@team.id}/#{path}"
        return path unless @season_id
        path + "/#{@season_id}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
chgk_rating-1.0.0.rc1 lib/chgk_rating/collections/tournaments.rb