chgk_rating 2.1.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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/Gemfile +3 -1
  4. data/LICENSE +1 -1
  5. data/README.md +4 -4
  6. data/Rakefile +4 -2
  7. data/chgk_rating.gemspec +19 -12
  8. data/lib/chgk_rating/attribute_mappings.rb +107 -108
  9. data/lib/chgk_rating/chgk_object.rb +5 -1
  10. data/lib/chgk_rating/client.rb +4 -2
  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 +3 -1
  14. data/lib/chgk_rating/collections/ratings/team_ratings.rb +3 -1
  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 +12 -8
  18. data/lib/chgk_rating/collections/tournaments/tournament_team_players.rb +3 -1
  19. data/lib/chgk_rating/collections/tournaments/tournament_team_results.rb +3 -1
  20. data/lib/chgk_rating/collections/tournaments/tournament_teams.rb +4 -1
  21. data/lib/chgk_rating/collections/tournaments/tournaments.rb +12 -8
  22. data/lib/chgk_rating/concerns/searching.rb +10 -9
  23. data/lib/chgk_rating/connection.rb +10 -8
  24. data/lib/chgk_rating/error.rb +7 -5
  25. data/lib/chgk_rating/models/base.rb +23 -16
  26. data/lib/chgk_rating/models/player.rb +3 -1
  27. data/lib/chgk_rating/models/rating/player_rating.rb +3 -1
  28. data/lib/chgk_rating/models/rating/rating.rb +3 -1
  29. data/lib/chgk_rating/models/rating/team_rating.rb +3 -1
  30. data/lib/chgk_rating/models/recap.rb +3 -1
  31. data/lib/chgk_rating/models/team.rb +3 -1
  32. data/lib/chgk_rating/models/tournament/player_tournament.rb +3 -1
  33. data/lib/chgk_rating/models/tournament/tournament.rb +3 -1
  34. data/lib/chgk_rating/models/tournament/tournament_team.rb +3 -1
  35. data/lib/chgk_rating/models/tournament/tournament_team_player.rb +3 -1
  36. data/lib/chgk_rating/models/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 -36
  40. data/lib/chgk_rating/version.rb +4 -2
  41. data/lib/chgk_rating.rb +3 -1
  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 +61 -80
  46. data/spec/lib/chgk_rating/client_spec.rb +0 -247
  47. data/spec/lib/chgk_rating/collections/player_ratings_spec.rb +0 -15
  48. data/spec/lib/chgk_rating/collections/players_spec.rb +0 -45
  49. data/spec/lib/chgk_rating/collections/recaps_spec.rb +0 -21
  50. data/spec/lib/chgk_rating/collections/team_ratings_spec.rb +0 -25
  51. data/spec/lib/chgk_rating/collections/teams_spec.rb +0 -42
  52. data/spec/lib/chgk_rating/collections/tournaments/player_tournaments_spec.rb +0 -38
  53. data/spec/lib/chgk_rating/collections/tournaments/tournament_team_players_spec.rb +0 -18
  54. data/spec/lib/chgk_rating/collections/tournaments/tournament_team_results_spec.rb +0 -17
  55. data/spec/lib/chgk_rating/collections/tournaments/tournament_teams_spec.rb +0 -58
  56. data/spec/lib/chgk_rating/collections/tournaments/tournaments_spec.rb +0 -62
  57. data/spec/lib/chgk_rating/models/base_spec.rb +0 -34
  58. data/spec/lib/chgk_rating/models/player_rating_spec.rb +0 -22
  59. data/spec/lib/chgk_rating/models/player_spec.rb +0 -62
  60. data/spec/lib/chgk_rating/models/recap_spec.rb +0 -35
  61. data/spec/lib/chgk_rating/models/team_rating_spec.rb +0 -27
  62. data/spec/lib/chgk_rating/models/team_spec.rb +0 -97
  63. data/spec/lib/chgk_rating/models/tournament/tournament_spec.rb +0 -95
  64. data/spec/lib/chgk_rating/models/tournament/tournament_team_player_spec.rb +0 -21
  65. data/spec/lib/chgk_rating/models/tournament/tournament_team_result_spec.rb +0 -19
  66. data/spec/lib/chgk_rating/models/tournament/tournament_team_spec.rb +0 -36
  67. data/spec/lib/chgk_rating/utils/snakecase_spec.rb +0 -12
  68. data/spec/lib/chgk_rating/utils/transformations_spec.rb +0 -16
  69. data/spec/lib/chgk_rating_spec.rb +0 -5
  70. data/spec/lib/ext/date_spec.rb +0 -7
  71. data/spec/lib/ext/date_time_spec.rb +0 -11
  72. data/spec/lib/ext/uri_spec.rb +0 -7
  73. data/spec/spec_helper.rb +0 -15
  74. data/spec/support/shared_examples.rb +0 -63
  75. data/spec/support/test_client.rb +0 -6
  76. data/spec/support/vcr.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2beed511c09dac149040e3ef7aa8b77b6544812b36b51edac684e59d31b3d13a
4
- data.tar.gz: 9095b4e10577fcce79635959cf5c59e6735991a542529d9297055f7d16f31619
3
+ metadata.gz: 61be2615dc148c3adab710b6a3d2fb2e2209ffff2414972101b94d3ba35ebbfe
4
+ data.tar.gz: d26da02ff2a2886e0c253106c6f1096bb1572d2db8a4d5476acb149f70d18653
5
5
  SHA512:
6
- metadata.gz: 3b46e4c6bc5bee3671c6a7eea8f01acc9de7eaba69d507e1c2c4dab48c03f8ec207f581e9c72adcb492146d036fb9357527e392604406a90e48e0327095f546a
7
- data.tar.gz: 959bf5cdc7e97d4448afdd7798fff377ce6101d546d33bf28df0b4944a24bdddf9cd08b9041a81d337e25d0321aa808411b84ca6b81997642b2535a9ac0357d1
6
+ metadata.gz: ea945aa9897881ecea27085dc0a224d33a2a0fb029a5624e7069a4831571bae5672effc2800b5d92e53e7d89f8b6856a5e925bf5a075843b1fcbe7e1c5b8532d
7
+ data.tar.gz: 52d3b312ebe06c301836562afa298de73f1a4682bd7d03057043f3883c08d23d2ece2725f2e0174291c69db0df9445c962260af255b64568c8c74c1b321ee418
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## v2.2.0 (2022-07-07)
4
+
5
+ * **Drop support for Ruby 2.4 and 2.5 (EOL)**
6
+ * Switched to Faraday v2 (thanks, @L-Eugene)
7
+ * Fixed various minor issues
8
+ * Switched to GH Actions
9
+ * Use Rubocop
10
+ * Update test matrix
11
+
3
12
  ## v2.1.0 (2021-12-29)
4
13
 
5
14
  * Updated API mappings (thanks, @L-Eugene)
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'http://rubygems.org'
2
4
 
3
- gemspec
5
+ gemspec
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2017 Ilya Bodrov
3
+ Copyright (c) 2022 Ilya Krukowski
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # ChgkRating
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/chgk_rating.svg)](https://badge.fury.io/rb/chgk_rating)
4
- [![Build Status](https://travis-ci.org/bodrovis/ChgkRating.svg?branch=master)](https://travis-ci.org/bodrovis/ChgkRating)
5
- [![Code Climate](https://codeclimate.com/github/bodrovis/ChgkRating/badges/gpa.svg)](https://codeclimate.com/github/bodrovis/ChgkRating)
4
+ ![CI](https://github.com/bodrovis/ChgkRating/actions/workflows/ci.yml/badge.svg)
5
+ [![Test Coverage](https://codecov.io/gh/bodrovis/ChgkRating/graph/badge.svg)](https://codecov.io/gh/bodrovis/ChgkRating)
6
6
 
7
- **This gem is in passive maintenance mode. I won't release any new features or introduce any complex enhancements as ChgkRating v1 is deprecated.**
7
+ **This gem is in passive maintenance mode. I won't release any new features or introduce any complex enhancements as ChgkRating v1 is deprecated. Please use [rating-chgk-v2 gem](https://github.com/bodrovis/rating-chgk-v2) which works with the new version of the API.**
8
8
 
9
9
  Ruby interface for the [rating.chgk.info](http://rating.chgk.info/index.php/api) WebAPI. This is not just a wrapper, but rather a quite complex opinionated client that allows to easily work with various API resources.
10
10
 
@@ -64,4 +64,4 @@ Tests run against mock responses so you don't need to perform any special setup.
64
64
 
65
65
  This plugin is licensed under the [MIT License](https://github.com/bodrovis/ChgkRating/blob/master/LICENSE).
66
66
 
67
- Copyright (c) [Ilya Bodrov](http://bodrovis.tech)
67
+ Copyright (c) [Ilya Krukowski](http://bodrovis.tech)
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake'
2
4
 
3
5
  begin
@@ -7,7 +9,7 @@ rescue LoadError
7
9
  puts 'although not required, bundler is recommened for running the tests'
8
10
  end
9
11
 
10
- task :default => :spec
12
+ task default: :spec
11
13
 
12
14
  require 'rspec/core/rake_task'
13
- RSpec::Core::RakeTask.new(:spec)
15
+ RSpec::Core::RakeTask.new(:spec)
data/chgk_rating.gemspec CHANGED
@@ -1,30 +1,37 @@
1
- require File.expand_path('../lib/chgk_rating/version', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('lib/chgk_rating/version', __dir__)
2
4
 
3
5
  Gem::Specification.new do |spec|
4
6
  spec.name = 'chgk_rating'
5
7
  spec.version = ChgkRating::VERSION
6
- spec.authors = ['Ilya Bodrov']
8
+ spec.authors = ['Ilya Krukowski']
7
9
  spec.email = ['golosizpru@gmail.com']
8
10
  spec.summary = 'Ruby interface to the competitive What? Where? When? rating API'
9
- spec.description = 'Opinionated Ruby client for the competitive What? Where? When? rating WebAPI (rating.chgk.info) that allows to work with data as with Ruby objects'
11
+ spec.description = 'Opinionated Ruby client for the competitive What? Where? When? ' \
12
+ 'rating WebAPI (rating.chgk.info) that ' \
13
+ 'allows to work with data as with Ruby objects'
10
14
  spec.homepage = 'http://chgk-rating.bodrovis.tech/'
11
15
  spec.license = 'MIT'
12
16
  spec.platform = Gem::Platform::RUBY
13
- spec.required_ruby_version = '>= 2.4.0'
17
+ spec.required_ruby_version = '>= 2.6.0'
14
18
 
15
- spec.files = Dir["README.md", "LICENSE", "CONTRIBUTING.md",
16
- "CHANGELOG.md", "lib/**/*.rb", "chgk_rating.gemspec", ".github/*.md",
17
- "Gemfile", "Rakefile"]
18
- spec.test_files = Dir["spec/**/*.rb"]
19
+ spec.files = Dir['README.md', 'LICENSE', 'CONTRIBUTING.md',
20
+ 'CHANGELOG.md', 'lib/**/*.rb', 'chgk_rating.gemspec', '.github/*.md',
21
+ 'Gemfile', 'Rakefile']
19
22
  spec.extra_rdoc_files = ['README.md']
20
23
  spec.require_paths = ['lib']
21
24
 
22
- spec.add_dependency 'faraday', '~> 1.8'
23
- spec.add_dependency 'faraday_middleware', '~> 1.2'
25
+ spec.add_dependency 'faraday', '~> 2.0'
26
+ spec.add_dependency 'faraday-follow_redirects', '~> 0.3'
24
27
  spec.add_dependency 'multi_json', '~> 1.15'
25
28
 
29
+ spec.add_development_dependency 'codecov', '~> 0.1'
26
30
  spec.add_development_dependency 'rake', '~> 13.0'
27
31
  spec.add_development_dependency 'rspec', '~> 3.6'
28
- spec.add_development_dependency 'vcr', '~> 6.0'
29
- spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
32
+ spec.add_development_dependency 'rubocop', '~> 1.31'
33
+ spec.add_development_dependency 'rubocop-performance', '~> 1.5'
34
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.11'
35
+ spec.add_development_dependency 'vcr', '~> 6.0'
36
+ spec.metadata['rubygems_mfa_required'] = 'true'
30
37
  end
@@ -1,14 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module AttributeMappings
3
5
  extend ChgkRating::Utils::Transformations
4
6
 
5
7
  class << self
6
8
  def find(name)
7
- begin
8
- const_get name.snakecase_upcase
9
- rescue NameError
10
- {}
11
- end
9
+ const_get name.snakecase_upcase
10
+ rescue NameError
11
+ {}
12
12
  end
13
13
 
14
14
  def generate_mappings_for(data)
@@ -20,21 +20,20 @@ module ChgkRating
20
20
  private
21
21
 
22
22
  def name_from(raw_name)
23
- { raw_name: raw_name.to_s }
23
+ {raw_name: raw_name.to_s}
24
24
  end
25
25
 
26
26
  def parse_raw_scheme(raw_scheme)
27
27
  if raw_scheme.respond_to? :inject
28
28
  scheme_from raw_scheme
29
29
  else
30
- { raw_scheme => name_from(raw_scheme) }
30
+ {raw_scheme => name_from(raw_scheme)}
31
31
  end
32
32
  end
33
33
 
34
34
  def scheme_from(raw_scheme)
35
- raw_scheme.inject({}) do |memo, (key, value)|
35
+ raw_scheme.each_with_object({}) do |(key, value), memo|
36
36
  memo[key] = scheme_value_from key, value
37
- memo
38
37
  end
39
38
  end
40
39
 
@@ -51,7 +50,7 @@ module ChgkRating
51
50
  return unless raw_schemes&.any?
52
51
 
53
52
  if raw_schemes.is_a? Array
54
- raw_schemes.inject({}) do |memo, raw_scheme|
53
+ raw_schemes.reduce({}) do |memo, raw_scheme|
55
54
  memo.merge parse_raw_scheme(raw_scheme)
56
55
  end
57
56
  else
@@ -61,107 +60,107 @@ module ChgkRating
61
60
  end
62
61
 
63
62
  generate_mappings_for({
64
- PLAYER: [
65
- { id: 'idplayer' },
66
- :name,
67
- :surname,
68
- :patronymic,
69
- :comment,
70
- :db_chgk_info_tag
71
- ],
72
- RATING: {
73
- release_id: 'idrelease',
74
- rating: [],
75
- rating_position: [],
76
- tech_rating: [],
77
- date: ['date', :date]
78
- },
79
- PLAYER_RATING: {
80
- player: ['idplayer', :player_id],
81
- tournaments_in_year: [],
82
- tournament_count_total: []
83
- },
84
- TEAM_RATING: {
85
- team: ['idteam', :team_id],
86
- 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]
87
113
  },
88
- RECAP: {
89
- season_id: 'idseason',
90
- team: ['idteam', :team_id],
91
- captain: ['captain', :player_id],
92
- 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]
93
144
  },
94
- PLAYER_TOURNAMENT: [
95
- tournament: ['idtournament', :tournament_id],
96
- team: ['idteam', :team_id],
97
- in_base_team: ['in_base_team', :boolean_binboolean]
98
- ],
99
- TOURNAMENT: [
100
- {
101
- id: 'idtournament',
102
- date_start: ['date_start', :datetime],
103
- date_end: ['date_end', :datetime],
104
- tour_count: [],
105
- tour_questions: [],
106
- tour_ques_per_tour: [],
107
- questions_total: [],
108
- main_payment_value: ['main_payment_value', :float],
109
- discounted_payment_value: ['discounted_payment_value', :float],
110
- tournament_in_rating: ['tournament_in_rating', :boolean_binboolean],
111
- date_requests_allowed_to: ['date_requests_allowed_to', :datetime],
112
- site_url: ['site_url', :uri],
113
- date_archived_at: ['date_archived_at', :datetime]
114
- },
115
- :name,
116
- :town,
117
- :long_name,
118
- :type_name,
119
- :main_payment_currency,
120
- :discounted_payment_currency,
121
- :discounted_payment_reason,
122
- :archive,
123
- :comment
124
- ],
125
- TOURNAMENT_TEAM_PLAYER: {
126
- id: 'idplayer',
127
- is_captain: ['is_captain', :boolean_binboolean],
128
- is_base: ['is_base', :boolean_binboolean],
129
- 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: []
130
153
  },
131
- TOURNAMENT_TEAM: [
132
- {
133
- id: 'idteam',
134
- position: ['position', :float],
135
- questions_total: [],
136
- result: ['mask', :splitboolean_arraystrboolean],
137
- bonus_b: [],
138
- tech_rating_rt: [],
139
- tech_rating_rg: [],
140
- tech_rating_rb: [],
141
- rating_r: [],
142
- predicted_position: [],
143
- diff_bonus: [],
144
- included_in_rating: ['included_in_rating', :boolean_binboolean]
145
- },
146
- :current_name,
147
- :base_name
148
- ],
149
- TEAM: [
150
- {
151
- id: 'idteam',
152
- tournaments_this_season: [],
153
- tournaments_total: []
154
- },
155
- :name,
156
- :town,
157
- :region_name,
158
- :country_name,
159
- :comment
160
- ],
161
- TOURNAMENT_TEAM_RESULT: {
162
- tour: [],
163
- result: ['mask', :arrayboolean_arraystrboolean]
164
- }
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
+ }
165
164
  })
166
165
  end
167
166
  end
@@ -1,14 +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)
9
12
  return unless obj
10
13
  return obj unless obj.is_a? klass
14
+
11
15
  obj&.id
12
16
  end
13
17
  end
14
- 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
@@ -138,7 +140,7 @@ module ChgkRating
138
140
  # @option params [String or Integer] :page The requested page. Default is 1
139
141
  def tournaments(team_or_id: nil, season_id: nil, params: {})
140
142
  ChgkRating::Collections::Tournaments.new params.merge(
141
- team: team_or_id, season_id: season_id
143
+ team: team_or_id, season_id: season_id
142
144
  )
143
145
  end
144
146
 
@@ -201,4 +203,4 @@ module ChgkRating
201
203
  team_at_tournament(tournament_or_id, team_or_id).players
202
204
  end
203
205
  end
204
- 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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Collections
3
5
  class PlayerRatings < Base
@@ -19,4 +21,4 @@ module ChgkRating
19
21
  end
20
22
  end
21
23
  end
22
- end
24
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Collections
3
5
  class TeamRatings < Base
@@ -19,4 +21,4 @@ module ChgkRating
19
21
  end
20
22
  end
21
23
  end
22
- 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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Collections
3
5
  class PlayerTournaments < Base
@@ -12,12 +14,12 @@ module ChgkRating
12
14
 
13
15
  def revert_to_hash(key, values)
14
16
  [
15
- key,
16
- {
17
- 'idplayer' => @player.id.to_s,
18
- 'idseason' => key,
19
- 'tournaments' => values.map(&:to_h)
20
- }
17
+ key,
18
+ {
19
+ 'idplayer' => @player.id.to_s,
20
+ 'idseason' => key,
21
+ 'tournaments' => values.map(&:to_h)
22
+ }
21
23
  ]
22
24
  end
23
25
 
@@ -33,12 +35,14 @@ module ChgkRating
33
35
  end
34
36
  end
35
37
 
36
- # @return [String] Either `tournaments`, `teams/ID/tournaments`, `players/ID/tournaments`, `teams/ID/tournaments/SEASON_ID`, `players/ID/tournaments/SEASON_ID`
38
+ # @return [String] Either `tournaments`, `teams/ID/tournaments`, `players/ID/tournaments`,
39
+ # `teams/ID/tournaments/SEASON_ID`, `players/ID/tournaments/SEASON_ID`
37
40
  def api_path
38
41
  path = "players/#{@player.id}/tournaments"
39
42
  return path unless @season_id
43
+
40
44
  path + "/#{@season_id}"
41
45
  end
42
46
  end
43
47
  end
44
- end
48
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Collections
3
5
  class TournamentTeamPlayers < Base
@@ -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