class ChgkRating::Collections::Tournaments

Attributes

season_id[R]
team[R]

Public Class Methods

new(params = {}) click to toggle source
Calls superclass method ChgkRating::Collections::Base::new
# File lib/chgk_rating/collections/tournaments.rb, line 6
def initialize(params = {})
  @team = build_model params[:team]

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

Public Instance Methods

revert_to_hash(key, values) click to toggle source
# File lib/chgk_rating/collections/tournaments.rb, line 14
def revert_to_hash(key, values)
  [
      key,
      {
          'idteam' => @team.id.to_s,
          'idseason' => key,
          'tournaments' => values.map(&:to_h)
      }
  ]
end

Private Instance Methods

api_path() click to toggle source
# File lib/chgk_rating/collections/tournaments.rb, line 38
def api_path
  path = 'tournaments'
  return path unless @team
  path = "teams/#{@team.id}/#{path}"
  return path unless @season_id
  path + "/#{@season_id}"
end
process(_results, params = {}) click to toggle source
Calls superclass method ChgkRating::Collections::Base#process
# File lib/chgk_rating/collections/tournaments.rb, line 27
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