chgk_rating 1.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -0
- data/Gemfile +3 -1
- data/LICENSE +1 -1
- data/README.md +10 -501
- data/Rakefile +4 -2
- data/chgk_rating.gemspec +23 -15
- data/lib/chgk_rating/attribute_mappings.rb +107 -80
- data/lib/chgk_rating/chgk_object.rb +6 -1
- data/lib/chgk_rating/client.rb +43 -10
- data/lib/chgk_rating/collections/base.rb +20 -15
- data/lib/chgk_rating/collections/players.rb +3 -1
- data/lib/chgk_rating/collections/ratings/player_ratings.rb +24 -0
- data/lib/chgk_rating/collections/{ratings.rb → ratings/team_ratings.rb} +5 -4
- data/lib/chgk_rating/collections/recaps.rb +4 -2
- data/lib/chgk_rating/collections/teams.rb +3 -1
- data/lib/chgk_rating/collections/tournaments/player_tournaments.rb +48 -0
- data/lib/chgk_rating/collections/{tournament_players.rb → tournaments/tournament_team_players.rb} +5 -3
- data/lib/chgk_rating/collections/{tournament_team_results.rb → tournaments/tournament_team_results.rb} +3 -1
- data/lib/chgk_rating/collections/{tournament_teams.rb → tournaments/tournament_teams.rb} +4 -1
- data/lib/chgk_rating/collections/{tournaments.rb → tournaments/tournaments.rb} +13 -8
- data/lib/chgk_rating/concerns/searching.rb +10 -9
- data/lib/chgk_rating/connection.rb +12 -7
- data/lib/chgk_rating/error.rb +7 -5
- data/lib/chgk_rating/models/base.rb +34 -15
- data/lib/chgk_rating/models/player.rb +28 -1
- data/lib/chgk_rating/models/rating/player_rating.rb +18 -0
- data/lib/chgk_rating/models/{tournament_player.rb → rating/rating.rb} +4 -2
- data/lib/chgk_rating/models/{rating.rb → rating/team_rating.rb} +4 -5
- data/lib/chgk_rating/models/recap.rb +3 -1
- data/lib/chgk_rating/models/team.rb +9 -7
- data/lib/chgk_rating/models/tournament/player_tournament.rb +10 -0
- data/lib/chgk_rating/models/{tournament.rb → tournament/tournament.rb} +7 -5
- data/lib/chgk_rating/models/{tournament_team.rb → tournament/tournament_team.rb} +6 -4
- data/lib/chgk_rating/models/tournament/tournament_team_player.rb +10 -0
- data/lib/chgk_rating/models/{tournament_team_result.rb → tournament/tournament_team_result.rb} +3 -1
- data/lib/chgk_rating/request.rb +10 -9
- data/lib/chgk_rating/utils/snakecase.rb +9 -7
- data/lib/chgk_rating/utils/transformations.rb +42 -35
- data/lib/chgk_rating/version.rb +4 -2
- data/lib/chgk_rating.rb +18 -11
- data/lib/ext/date.rb +6 -8
- data/lib/ext/date_time.rb +4 -2
- data/lib/ext/uri.rb +6 -6
- metadata +95 -90
- data/spec/lib/chgk_rating/client_spec.rb +0 -208
- data/spec/lib/chgk_rating/collections/players_spec.rb +0 -45
- data/spec/lib/chgk_rating/collections/ratings_spec.rb +0 -25
- data/spec/lib/chgk_rating/collections/recaps_spec.rb +0 -21
- data/spec/lib/chgk_rating/collections/teams_spec.rb +0 -42
- data/spec/lib/chgk_rating/collections/tournament_players_spec.rb +0 -18
- data/spec/lib/chgk_rating/collections/tournament_team_results_spec.rb +0 -17
- data/spec/lib/chgk_rating/collections/tournament_teams_spec.rb +0 -60
- data/spec/lib/chgk_rating/collections/tournaments_spec.rb +0 -62
- data/spec/lib/chgk_rating/models/base_spec.rb +0 -34
- data/spec/lib/chgk_rating/models/player_spec.rb +0 -35
- data/spec/lib/chgk_rating/models/rating_spec.rb +0 -27
- data/spec/lib/chgk_rating/models/recap_spec.rb +0 -35
- data/spec/lib/chgk_rating/models/team_spec.rb +0 -89
- data/spec/lib/chgk_rating/models/tournament_player_spec.rb +0 -21
- data/spec/lib/chgk_rating/models/tournament_spec.rb +0 -92
- data/spec/lib/chgk_rating/models/tournament_team_result_spec.rb +0 -19
- data/spec/lib/chgk_rating/models/tournament_team_spec.rb +0 -36
- data/spec/lib/chgk_rating/utils/snakecase_spec.rb +0 -12
- data/spec/lib/chgk_rating/utils/transformations_spec.rb +0 -16
- data/spec/lib/chgk_rating_spec.rb +0 -5
- data/spec/lib/ext/date_spec.rb +0 -7
- data/spec/lib/ext/date_time_spec.rb +0 -11
- data/spec/lib/ext/uri_spec.rb +0 -7
- data/spec/spec_helper.rb +0 -13
- data/spec/support/shared_examples.rb +0 -63
- data/spec/support/test_client.rb +0 -6
- 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
|
-
{
|
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
|
-
{
|
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.
|
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.
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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
|
data/lib/chgk_rating/client.rb
CHANGED
@@ -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).
|
52
|
+
tournament(tournament_or_id, true).team_by(team_or_id)
|
51
53
|
end
|
52
54
|
|
53
|
-
# Returns
|
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::
|
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
|
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(
|
142
|
+
ChgkRating::Collections::Tournaments.new params.merge(
|
143
|
+
team: team_or_id, season_id: season_id
|
144
|
+
)
|
131
145
|
end
|
132
146
|
|
133
|
-
# Returns
|
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
|
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
|
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::
|
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
|
-
|
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
|
26
|
-
|
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
|
31
|
-
|
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
|
37
|
-
|
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 &&
|
45
|
-
|
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.
|
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.
|
64
|
-
return raw_results['items'] if raw_results.
|
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
|
79
|
+
results.map(&block)
|
75
80
|
end
|
76
81
|
end
|
77
82
|
end
|
78
83
|
end
|
79
|
-
end
|
84
|
+
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
|
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::
|
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
|
@@ -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
|
data/lib/chgk_rating/collections/{tournament_players.rb → tournaments/tournament_team_players.rb}
RENAMED
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ChgkRating
|
2
4
|
module Collections
|
3
|
-
class
|
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::
|
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,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
|