chgk_rating 1.0.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +32 -0
  3. data/Gemfile +3 -1
  4. data/LICENSE +1 -1
  5. data/README.md +10 -501
  6. data/Rakefile +4 -2
  7. data/chgk_rating.gemspec +23 -15
  8. data/lib/chgk_rating/attribute_mappings.rb +107 -80
  9. data/lib/chgk_rating/chgk_object.rb +6 -1
  10. data/lib/chgk_rating/client.rb +43 -10
  11. data/lib/chgk_rating/collections/base.rb +20 -15
  12. data/lib/chgk_rating/collections/players.rb +3 -1
  13. data/lib/chgk_rating/collections/ratings/player_ratings.rb +24 -0
  14. data/lib/chgk_rating/collections/{ratings.rb → ratings/team_ratings.rb} +5 -4
  15. data/lib/chgk_rating/collections/recaps.rb +4 -2
  16. data/lib/chgk_rating/collections/teams.rb +3 -1
  17. data/lib/chgk_rating/collections/tournaments/player_tournaments.rb +48 -0
  18. data/lib/chgk_rating/collections/{tournament_players.rb → tournaments/tournament_team_players.rb} +5 -3
  19. data/lib/chgk_rating/collections/{tournament_team_results.rb → tournaments/tournament_team_results.rb} +3 -1
  20. data/lib/chgk_rating/collections/{tournament_teams.rb → tournaments/tournament_teams.rb} +4 -1
  21. data/lib/chgk_rating/collections/{tournaments.rb → tournaments/tournaments.rb} +13 -8
  22. data/lib/chgk_rating/concerns/searching.rb +10 -9
  23. data/lib/chgk_rating/connection.rb +12 -7
  24. data/lib/chgk_rating/error.rb +7 -5
  25. data/lib/chgk_rating/models/base.rb +34 -15
  26. data/lib/chgk_rating/models/player.rb +28 -1
  27. data/lib/chgk_rating/models/rating/player_rating.rb +18 -0
  28. data/lib/chgk_rating/models/{tournament_player.rb → rating/rating.rb} +4 -2
  29. data/lib/chgk_rating/models/{rating.rb → rating/team_rating.rb} +4 -5
  30. data/lib/chgk_rating/models/recap.rb +3 -1
  31. data/lib/chgk_rating/models/team.rb +9 -7
  32. data/lib/chgk_rating/models/tournament/player_tournament.rb +10 -0
  33. data/lib/chgk_rating/models/{tournament.rb → tournament/tournament.rb} +7 -5
  34. data/lib/chgk_rating/models/{tournament_team.rb → tournament/tournament_team.rb} +6 -4
  35. data/lib/chgk_rating/models/tournament/tournament_team_player.rb +10 -0
  36. data/lib/chgk_rating/models/{tournament_team_result.rb → tournament/tournament_team_result.rb} +3 -1
  37. data/lib/chgk_rating/request.rb +10 -9
  38. data/lib/chgk_rating/utils/snakecase.rb +9 -7
  39. data/lib/chgk_rating/utils/transformations.rb +42 -35
  40. data/lib/chgk_rating/version.rb +4 -2
  41. data/lib/chgk_rating.rb +18 -11
  42. data/lib/ext/date.rb +6 -8
  43. data/lib/ext/date_time.rb +4 -2
  44. data/lib/ext/uri.rb +6 -6
  45. metadata +95 -90
  46. data/spec/lib/chgk_rating/client_spec.rb +0 -208
  47. data/spec/lib/chgk_rating/collections/players_spec.rb +0 -45
  48. data/spec/lib/chgk_rating/collections/ratings_spec.rb +0 -25
  49. data/spec/lib/chgk_rating/collections/recaps_spec.rb +0 -21
  50. data/spec/lib/chgk_rating/collections/teams_spec.rb +0 -42
  51. data/spec/lib/chgk_rating/collections/tournament_players_spec.rb +0 -18
  52. data/spec/lib/chgk_rating/collections/tournament_team_results_spec.rb +0 -17
  53. data/spec/lib/chgk_rating/collections/tournament_teams_spec.rb +0 -60
  54. data/spec/lib/chgk_rating/collections/tournaments_spec.rb +0 -62
  55. data/spec/lib/chgk_rating/models/base_spec.rb +0 -34
  56. data/spec/lib/chgk_rating/models/player_spec.rb +0 -35
  57. data/spec/lib/chgk_rating/models/rating_spec.rb +0 -27
  58. data/spec/lib/chgk_rating/models/recap_spec.rb +0 -35
  59. data/spec/lib/chgk_rating/models/team_spec.rb +0 -89
  60. data/spec/lib/chgk_rating/models/tournament_player_spec.rb +0 -21
  61. data/spec/lib/chgk_rating/models/tournament_spec.rb +0 -92
  62. data/spec/lib/chgk_rating/models/tournament_team_result_spec.rb +0 -19
  63. data/spec/lib/chgk_rating/models/tournament_team_spec.rb +0 -36
  64. data/spec/lib/chgk_rating/utils/snakecase_spec.rb +0 -12
  65. data/spec/lib/chgk_rating/utils/transformations_spec.rb +0 -16
  66. data/spec/lib/chgk_rating_spec.rb +0 -5
  67. data/spec/lib/ext/date_spec.rb +0 -7
  68. data/spec/lib/ext/date_time_spec.rb +0 -11
  69. data/spec/lib/ext/uri_spec.rb +0 -7
  70. data/spec/spec_helper.rb +0 -13
  71. data/spec/support/shared_examples.rb +0 -63
  72. data/spec/support/test_client.rb +0 -6
  73. data/spec/support/vcr.rb +0 -11
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module AttributeMappings
3
5
  extend ChgkRating::Utils::Transformations
@@ -5,6 +7,8 @@ module ChgkRating
5
7
  class << self
6
8
  def find(name)
7
9
  const_get name.snakecase_upcase
10
+ rescue NameError
11
+ {}
8
12
  end
9
13
 
10
14
  def generate_mappings_for(data)
@@ -16,21 +20,20 @@ module ChgkRating
16
20
  private
17
21
 
18
22
  def name_from(raw_name)
19
- { raw_name: raw_name.to_s }
23
+ {raw_name: raw_name.to_s}
20
24
  end
21
25
 
22
26
  def parse_raw_scheme(raw_scheme)
23
27
  if raw_scheme.respond_to? :inject
24
28
  scheme_from raw_scheme
25
29
  else
26
- { raw_scheme => name_from(raw_scheme) }
30
+ {raw_scheme => name_from(raw_scheme)}
27
31
  end
28
32
  end
29
33
 
30
34
  def scheme_from(raw_scheme)
31
- raw_scheme.inject({}) do |memo, (key, value)|
35
+ raw_scheme.each_with_object({}) do |(key, value), memo|
32
36
  memo[key] = scheme_value_from key, value
33
- memo
34
37
  end
35
38
  end
36
39
 
@@ -47,7 +50,7 @@ module ChgkRating
47
50
  return unless raw_schemes&.any?
48
51
 
49
52
  if raw_schemes.is_a? Array
50
- raw_schemes.inject({}) do |memo, raw_scheme|
53
+ raw_schemes.reduce({}) do |memo, raw_scheme|
51
54
  memo.merge parse_raw_scheme(raw_scheme)
52
55
  end
53
56
  else
@@ -57,83 +60,107 @@ module ChgkRating
57
60
  end
58
61
 
59
62
  generate_mappings_for({
60
- PLAYER: [
61
- { id: 'idplayer' },
62
- :name,
63
- :surname,
64
- :patronymic,
65
- :comment,
66
- :db_chgk_info_tag
67
- ],
68
- RATING: {
69
- team: ['idteam', :team_id],
70
- release_id: 'idrelease',
71
- rating: [],
72
- rating_position: [],
73
- date: ['date', :date],
74
- formula: ['formula', :sym]
63
+ PLAYER: [
64
+ {id: 'idplayer'},
65
+ :name,
66
+ :surname,
67
+ :patronymic,
68
+ :comment,
69
+ :db_chgk_info_tag
70
+ ],
71
+ RATING: {
72
+ release_id: 'idrelease',
73
+ rating: [],
74
+ rating_position: [],
75
+ tech_rating: [],
76
+ date: ['date', :date]
77
+ },
78
+ PLAYER_RATING: {
79
+ player: ['idplayer', :player_id],
80
+ tournaments_in_year: [],
81
+ tournament_count_total: []
82
+ },
83
+ TEAM_RATING: {
84
+ team: ['idteam', :team_id],
85
+ formula: ['formula', :sym]
86
+ },
87
+ RECAP: {
88
+ season_id: 'idseason',
89
+ team: ['idteam', :team_id],
90
+ captain: ['captain', :player_id],
91
+ players: ['players', :players_ids]
92
+ },
93
+ PLAYER_TOURNAMENT: [
94
+ tournament: ['idtournament', :tournament_id],
95
+ team: ['idteam', :team_id],
96
+ in_base_team: ['in_base_team', :boolean_binboolean]
97
+ ],
98
+ TOURNAMENT: [
99
+ {
100
+ id: 'idtournament',
101
+ date_start: ['date_start', :datetime],
102
+ date_end: ['date_end', :datetime],
103
+ tour_count: [],
104
+ tour_questions: [],
105
+ tour_ques_per_tour: [],
106
+ questions_total: [],
107
+ main_payment_value: ['main_payment_value', :float],
108
+ discounted_payment_value: ['discounted_payment_value', :float],
109
+ tournament_in_rating: ['tournament_in_rating', :boolean_binboolean],
110
+ date_requests_allowed_to: ['date_requests_allowed_to', :datetime],
111
+ site_url: ['site_url', :uri],
112
+ date_archived_at: ['date_archived_at', :datetime]
75
113
  },
76
- RECAP: {
77
- season_id: 'idseason',
78
- team: ['idteam', :team_id],
79
- captain: ['captain', :player_id],
80
- players: ['players', :players_ids]
114
+ :name,
115
+ :town,
116
+ :long_name,
117
+ :type_name,
118
+ :main_payment_currency,
119
+ :discounted_payment_currency,
120
+ :discounted_payment_reason,
121
+ :archive,
122
+ :comment
123
+ ],
124
+ TOURNAMENT_TEAM_PLAYER: {
125
+ id: 'idplayer',
126
+ is_captain: ['is_captain', :boolean_binboolean],
127
+ is_base: ['is_base', :boolean_binboolean],
128
+ is_foreign: ['is_foreign', :boolean_binboolean]
129
+ },
130
+ TOURNAMENT_TEAM: [
131
+ {
132
+ id: 'idteam',
133
+ position: ['position', :float],
134
+ questions_total: [],
135
+ result: ['mask', :splitboolean_arraystrboolean],
136
+ bonus_b: [],
137
+ tech_rating_rt: [],
138
+ tech_rating_rg: [],
139
+ tech_rating_rb: [],
140
+ rating_r: [],
141
+ predicted_position: [],
142
+ diff_bonus: [],
143
+ included_in_rating: ['included_in_rating', :boolean_binboolean]
81
144
  },
82
- TOURNAMENT: [
83
- {
84
- id: 'idtournament',
85
- date_start: ['date_start', :datetime],
86
- date_end: ['date_end', :datetime],
87
- tour_count: [],
88
- tour_questions: [],
89
- tour_ques_per_tour: [],
90
- questions_total: [],
91
- main_payment_value: ['main_payment_value', :float],
92
- discounted_payment_value: ['discounted_payment_value', :float],
93
- date_requests_allowed_to: ['date_requests_allowed_to', :datetime],
94
- site_url: ['site_url', :uri]
95
- },
96
- :name,
97
- :town,
98
- :long_name,
99
- :type_name,
100
- :discounted_payment_reason,
101
- :comment
102
- ],
103
- TOURNAMENT_PLAYER: {
104
- id: 'idplayer',
105
- is_captain: ['is_captain', :boolean_binboolean],
106
- is_base: ['is_base', :boolean_binboolean],
107
- is_foreign: ['is_foreign', :boolean_binboolean]
145
+ :current_name,
146
+ :base_name
147
+ ],
148
+ TEAM: [
149
+ {
150
+ id: 'idteam',
151
+ tournaments_this_season: [],
152
+ tournaments_total: []
108
153
  },
109
- TOURNAMENT_TEAM: [
110
- {
111
- id: 'idteam',
112
- position: ['position', :float],
113
- questions_total: [],
114
- result: ['mask', :splitboolean_arraystrboolean],
115
- bonus_a: [],
116
- bonus_b: [],
117
- tech_rating: [],
118
- predicted_position: [],
119
- d_bonus_a: [],
120
- d_bonus_b: [],
121
- d_diff_bonus: [],
122
- included_in_rating: ['included_in_rating', :boolean_binboolean]
123
- },
124
- :current_name,
125
- :base_name
126
- ],
127
- TEAM: [
128
- { id: 'idteam' },
129
- :name,
130
- :town,
131
- :comment
132
- ],
133
- TOURNAMENT_TEAM_RESULT: {
134
- tour: [],
135
- result: ['mask', :arrayboolean_arraystrboolean]
136
- }
154
+ :name,
155
+ :town,
156
+ :region_name,
157
+ :country_name,
158
+ :comment
159
+ ],
160
+ TOURNAMENT_TEAM_RESULT: {
161
+ tour: [],
162
+ result: ['mask', :arrayboolean_arraystrboolean]
163
+ }
137
164
  })
138
165
  end
139
- end
166
+ end
@@ -1,13 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  class ChgkObject
3
5
  def build_model(object, klass = ChgkRating::Models::Team, params = {lazy: true})
4
6
  return unless object
7
+
5
8
  object.instance_of?(klass) ? object : klass.new(object, params)
6
9
  end
7
10
 
8
11
  def extract_id_from(obj, klass = ChgkRating::Models::Team)
12
+ return unless obj
9
13
  return obj unless obj.is_a? klass
14
+
10
15
  obj&.id
11
16
  end
12
17
  end
13
- end
18
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  class Client
3
5
  # Returns a single Team
@@ -47,19 +49,29 @@ module ChgkRating
47
49
  # @param tournament_or_id [String, Integer or Tournament] Tournament to load team for.
48
50
  # @param team_or_id [String, Integer or Team] Team to search for.
49
51
  def team_at_tournament(tournament_or_id, team_or_id)
50
- tournament(tournament_or_id, true).team(team_or_id)
52
+ tournament(tournament_or_id, true).team_by(team_or_id)
51
53
  end
52
54
 
53
- # Returns Rating for a given Team in a given release
55
+ # Returns rating for a given Team in a given release
54
56
  #
55
57
  # @raise [ChgkRating::Error::NotFound] Error raised when the requested release or Team cannot be found.
56
- # @return [ChgkRating::Models::Rating] The requested Rating.
58
+ # @return [ChgkRating::Models::TeamRating] The requested rating.
57
59
  # @param team_or_id [String, Integer or ChgkRating::Models::Team] Team to load rating for.
58
60
  # @param release_id [String or Integer] Release to load rating for.
59
- def rating(team_or_id, release_id)
61
+ def team_rating(team_or_id, release_id)
60
62
  team(team_or_id, true).rating(release_id)
61
63
  end
62
64
 
65
+ # Returns rating for a given Player in a given release
66
+ #
67
+ # @raise [ChgkRating::Error::NotFound] Error raised when the requested release or Player cannot be found.
68
+ # @return [ChgkRating::Models::PlayerRating] The requested rating.
69
+ # @param player_or_id [String, Integer or ChgkRating::Models::Team] Player to load rating for.
70
+ # @param release_id [String or Integer] Release to load rating for.
71
+ def player_rating(player_or_id, release_id)
72
+ player(player_or_id, true).rating(release_id)
73
+ end
74
+
63
75
  # Search
64
76
 
65
77
  # Returns a Players collection based on the search criteria.
@@ -127,18 +139,39 @@ module ChgkRating
127
139
  # @param season_id [String or Integer] Season to load tournaments for
128
140
  # @option params [String or Integer] :page The requested page. Default is 1
129
141
  def tournaments(team_or_id: nil, season_id: nil, params: {})
130
- ChgkRating::Collections::Tournaments.new params.merge(team: team_or_id, season_id: season_id)
142
+ ChgkRating::Collections::Tournaments.new params.merge(
143
+ team: team_or_id, season_id: season_id
144
+ )
131
145
  end
132
146
 
133
- # Returns an array-like Ratings collection for a given team.
147
+ # Returns a collection of Tournaments that the Player has participated in
148
+ #
149
+ # @return [ChgkRating::Collection::PlayerTournaments] The collection of tournaments.
150
+ # @param player_or_id [String, Integer or ChgkRating::Models::Player] Player to load tournaments for.
151
+ # @param season_id [String or Integer] Season to load tournaments for
152
+ def player_tournaments(player_or_id, season_id = nil)
153
+ ChgkRating::Collections::PlayerTournaments.new player: player_or_id,
154
+ season_id: season_id
155
+ end
156
+
157
+ # Returns an array-like Ratings collection for a given Team.
134
158
  #
135
159
  # @raise [ChgkRating::Error::NotFound] Error raised when the requested Team cannot be found.
136
160
  # @return [ChgkRating::Collection::Ratings] The collection of ratings.
137
161
  # @param team_or_id [String, Integer or ChgkRating::Models::Team] Team to load ratings for.
138
- def ratings(team_or_id)
162
+ def team_ratings(team_or_id)
139
163
  team(team_or_id, true).ratings
140
164
  end
141
165
 
166
+ # Returns an array-like Ratings collection for a given Player.
167
+ #
168
+ # @raise [ChgkRating::Error::NotFound] Error raised when the requested Player cannot be found.
169
+ # @return [ChgkRating::Collection::Ratings] The collection of ratings.
170
+ # @param player_or_id [String, Integer or ChgkRating::Models::Team] Player to load ratings for.
171
+ def player_ratings(player_or_id)
172
+ player(player_or_id, true).ratings
173
+ end
174
+
142
175
  # Returns an array-like TournamentTeams collection specifying which teams participated in a given tournament
143
176
  #
144
177
  # @raise [ChgkRating::Error::NotFound] Error raised when the requested Tournament cannot be found.
@@ -159,15 +192,15 @@ module ChgkRating
159
192
  team_at_tournament(tournament_or_id, team_or_id).results
160
193
  end
161
194
 
162
- # Returns an array-like TournamentPlayers collection containing roster for a
195
+ # Returns an array-like TournamentTeamPlayers collection containing roster for a
163
196
  # given team at a given tournament.
164
197
  #
165
198
  # @raise [ChgkRating::Error::NotFound] Error raised when the requested Tournament or Team cannot be found.
166
- # @return [ChgkRating::Collection::TournamentPlayers] The collection of results.
199
+ # @return [ChgkRating::Collection::TournamentTeamPlayers] The collection of results.
167
200
  # @param tournament_or_id [String, Integer or ChgkRating::Models::Tournament] Tournament to load players for.
168
201
  # @param team_or_id [String, Integer or ChgkRating::Models::Team] Team to load players for.
169
202
  def team_players_at_tournament(tournament_or_id, team_or_id)
170
203
  team_at_tournament(tournament_or_id, team_or_id).players
171
204
  end
172
205
  end
173
- end
206
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Collections
3
5
  class Base < ChgkObject
@@ -8,7 +10,7 @@ module ChgkRating
8
10
 
9
11
  def initialize(params = {})
10
12
  results = params[:collection] ||
11
- prepare(get(api_path, build_request_params_from(params)))
13
+ prepare(get(api_path, build_request_params_from(params)))
12
14
 
13
15
  @items = process results, params
14
16
  end
@@ -22,27 +24,30 @@ module ChgkRating
22
24
  end
23
25
 
24
26
  def to_a
25
- raise ChgkRating::Error::NotArrayType unless self.respond_to?(:to_a)
26
- self.items.to_a.map &:to_h
27
+ raise ChgkRating::Error::NotArrayType unless respond_to?(:to_a)
28
+
29
+ items.to_a.map(&:to_h)
27
30
  end
28
31
 
29
32
  def to_h
30
- raise ChgkRating::Error::NotHashType unless self.respond_to?(:to_h)
31
- self.items.map { |k,v| revert_to_hash(k, v) }.to_h
33
+ raise ChgkRating::Error::NotHashType unless respond_to?(:to_h)
34
+
35
+ items.to_h { |k, v| revert_to_hash(k, v) }
32
36
  end
33
37
 
34
38
  def respond_to?(method, include_all = false)
35
39
  method = method.to_sym
36
- if %i( to_a to_h ).include?(method.to_sym)
37
- self.convertable? method
40
+ if %i[to_a to_h].include?(method.to_sym)
41
+ convertable? method
38
42
  else
39
43
  super
40
44
  end
41
45
  end
42
46
 
43
47
  def convertable?(method)
44
- return true if (method == :to_a && self.items.is_a?(Array)) ||
45
- (method == :to_h && self.items.is_a?(Hash))
48
+ return true if (method == :to_a && items.is_a?(Array)) ||
49
+ (method == :to_h && items.is_a?(Hash))
50
+
46
51
  false
47
52
  end
48
53
 
@@ -54,26 +59,26 @@ module ChgkRating
54
59
 
55
60
  def build_request_params_from(params)
56
61
  request_params = params[:request].to_h
57
- request_params[:page] = params.delete(:page).to_i if params.has_key?(:page)
62
+ request_params[:page] = params.delete(:page).to_i if params.key?(:page)
58
63
  request_params
59
64
  end
60
65
 
61
66
  def prepare(raw_results)
62
67
  if raw_results.respond_to?(:has_key?)
63
- return raw_results['tournaments'] if raw_results.has_key?('tournaments')
64
- return raw_results['items'] if raw_results.has_key?('items')
68
+ return raw_results['tournaments'] if raw_results.key?('tournaments')
69
+ return raw_results['items'] if raw_results.key?('items')
65
70
  end
66
71
 
67
72
  raw_results
68
73
  end
69
74
 
70
- def process(results, *_args)
75
+ def process(results, *_args, &block)
71
76
  if results.is_a? Hash
72
77
  results.each { |season, result| results[season] = yield result }
73
78
  else
74
- results.map { |result| yield result }
79
+ results.map(&block)
75
80
  end
76
81
  end
77
82
  end
78
83
  end
79
- end
84
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Collections
3
5
  class Players < Base
@@ -14,4 +16,4 @@ module ChgkRating
14
16
  end
15
17
  end
16
18
  end
17
- end
19
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ChgkRating
4
+ module Collections
5
+ class PlayerRatings < Base
6
+ attr_reader :player
7
+
8
+ def initialize(params = {})
9
+ @player = build_model params[:player], ChgkRating::Models::Player
10
+ super
11
+ end
12
+
13
+ private
14
+
15
+ def process(*_args)
16
+ super { |result| ChgkRating::Models::PlayerRating.new result }
17
+ end
18
+
19
+ def api_path
20
+ "players/#{@player.id}/rating"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,18 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Collections
3
- class Ratings < Base
5
+ class TeamRatings < Base
4
6
  attr_reader :team
5
7
 
6
8
  def initialize(params = {})
7
9
  @team = build_model params[:team]
8
-
9
10
  super
10
11
  end
11
12
 
12
13
  private
13
14
 
14
15
  def process(*_args)
15
- super { |result| ChgkRating::Models::Rating.new result }
16
+ super { |result| ChgkRating::Models::TeamRating.new result }
16
17
  end
17
18
 
18
19
  def api_path
@@ -20,4 +21,4 @@ module ChgkRating
20
21
  end
21
22
  end
22
23
  end
23
- end
24
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Collections
3
5
  class Recaps < Base
@@ -12,7 +14,7 @@ module ChgkRating
12
14
  private
13
15
 
14
16
  def process(results, _params)
15
- results.each do |season,value|
17
+ results.each do |season, value|
16
18
  results[season] = ChgkRating::Models::Recap.new value, team: @team
17
19
  end
18
20
  end
@@ -22,4 +24,4 @@ module ChgkRating
22
24
  end
23
25
  end
24
26
  end
25
- end
27
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Collections
3
5
  class Teams < Base
@@ -14,4 +16,4 @@ module ChgkRating
14
16
  end
15
17
  end
16
18
  end
17
- end
19
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ChgkRating
4
+ module Collections
5
+ class PlayerTournaments < Base
6
+ attr_reader :season_id, :player
7
+
8
+ def initialize(params = {})
9
+ @player = build_model params[:player], ChgkRating::Models::Player
10
+
11
+ @season_id = params[:season_id]
12
+ super
13
+ end
14
+
15
+ def revert_to_hash(key, values)
16
+ [
17
+ key,
18
+ {
19
+ 'idplayer' => @player.id.to_s,
20
+ 'idseason' => key,
21
+ 'tournaments' => values.map(&:to_h)
22
+ }
23
+ ]
24
+ end
25
+
26
+ private
27
+
28
+ def process(_results, params = {})
29
+ super do |result|
30
+ if @player && @season_id.nil?
31
+ ChgkRating::Collections::PlayerTournaments.new(collection: result['tournaments']).items
32
+ else
33
+ ChgkRating::Models::PlayerTournament.new result
34
+ end
35
+ end
36
+ end
37
+
38
+ # @return [String] Either `tournaments`, `teams/ID/tournaments`, `players/ID/tournaments`,
39
+ # `teams/ID/tournaments/SEASON_ID`, `players/ID/tournaments/SEASON_ID`
40
+ def api_path
41
+ path = "players/#{@player.id}/tournaments"
42
+ return path unless @season_id
43
+
44
+ path + "/#{@season_id}"
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Collections
3
- class TournamentPlayers < Base
5
+ class TournamentTeamPlayers < Base
4
6
  attr_reader :team, :tournament
5
7
 
6
8
  def initialize(params = {})
@@ -13,7 +15,7 @@ module ChgkRating
13
15
  private
14
16
 
15
17
  def process(*_args)
16
- super { |result| ChgkRating::Models::TournamentPlayer.new result }
18
+ super { |result| ChgkRating::Models::TournamentTeamPlayer.new result }
17
19
  end
18
20
 
19
21
  def api_path
@@ -21,4 +23,4 @@ module ChgkRating
21
23
  end
22
24
  end
23
25
  end
24
- end
26
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Collections
3
5
  class TournamentTeamResults < Base
@@ -21,4 +23,4 @@ module ChgkRating
21
23
  end
22
24
  end
23
25
  end
24
- end
26
+ end
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Collections
3
5
  class TournamentTeams < Base
4
6
  attr_reader :tournament
7
+
5
8
  def initialize(params = {})
6
9
  @tournament = build_model params[:tournament], ChgkRating::Models::Tournament
7
10
 
@@ -19,4 +22,4 @@ module ChgkRating
19
22
  end
20
23
  end
21
24
  end
22
- end
25
+ end