chgk_rating 1.0.0.rc1 → 1.0.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 (70) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +12 -12
  3. data/.github/PULL_REQUEST_TEMPLATE.md +10 -10
  4. data/CHANGELOG.md +7 -0
  5. data/Gemfile +2 -6
  6. data/LICENSE +21 -21
  7. data/README.md +2 -1
  8. data/Rakefile +12 -12
  9. data/chgk_rating.gemspec +28 -28
  10. data/lib/chgk_rating.rb +51 -52
  11. data/lib/chgk_rating/attribute_mappings.rb +138 -137
  12. data/lib/chgk_rating/chgk_object.rb +12 -12
  13. data/lib/chgk_rating/client.rb +172 -172
  14. data/lib/chgk_rating/collections/base.rb +78 -78
  15. data/lib/chgk_rating/collections/players.rb +16 -16
  16. data/lib/chgk_rating/collections/ratings.rb +22 -22
  17. data/lib/chgk_rating/collections/recaps.rb +24 -24
  18. data/lib/chgk_rating/collections/teams.rb +16 -16
  19. data/lib/chgk_rating/collections/tournament_players.rb +23 -23
  20. data/lib/chgk_rating/collections/tournament_team_results.rb +23 -23
  21. data/lib/chgk_rating/collections/tournament_teams.rb +21 -21
  22. data/lib/chgk_rating/collections/tournaments.rb +46 -46
  23. data/lib/chgk_rating/concerns/searching.rb +24 -20
  24. data/lib/chgk_rating/connection.rb +18 -18
  25. data/lib/chgk_rating/error.rb +45 -45
  26. data/lib/chgk_rating/models/base.rb +89 -89
  27. data/lib/chgk_rating/models/player.rb +10 -10
  28. data/lib/chgk_rating/models/rating.rb +18 -18
  29. data/lib/chgk_rating/models/recap.rb +18 -18
  30. data/lib/chgk_rating/models/team.rb +61 -61
  31. data/lib/chgk_rating/models/tournament.rb +45 -45
  32. data/lib/chgk_rating/models/tournament_player.rb +7 -7
  33. data/lib/chgk_rating/models/tournament_team.rb +28 -28
  34. data/lib/chgk_rating/models/tournament_team_result.rb +7 -7
  35. data/lib/chgk_rating/request.rb +31 -31
  36. data/lib/chgk_rating/utils/snakecase.rb +15 -15
  37. data/lib/chgk_rating/utils/transformations.rb +82 -82
  38. data/lib/chgk_rating/version.rb +2 -2
  39. data/lib/ext/date.rb +10 -10
  40. data/lib/ext/date_time.rb +4 -4
  41. data/lib/ext/uri.rb +8 -8
  42. data/spec/lib/chgk_rating/client_spec.rb +207 -197
  43. data/spec/lib/chgk_rating/collections/players_spec.rb +44 -44
  44. data/spec/lib/chgk_rating/collections/ratings_spec.rb +24 -24
  45. data/spec/lib/chgk_rating/collections/recaps_spec.rb +20 -20
  46. data/spec/lib/chgk_rating/collections/teams_spec.rb +41 -41
  47. data/spec/lib/chgk_rating/collections/tournament_players_spec.rb +17 -17
  48. data/spec/lib/chgk_rating/collections/tournament_team_results_spec.rb +16 -16
  49. data/spec/lib/chgk_rating/collections/tournament_teams_spec.rb +59 -57
  50. data/spec/lib/chgk_rating/collections/tournaments_spec.rb +61 -61
  51. data/spec/lib/chgk_rating/models/base_spec.rb +33 -33
  52. data/spec/lib/chgk_rating/models/player_spec.rb +34 -34
  53. data/spec/lib/chgk_rating/models/rating_spec.rb +26 -26
  54. data/spec/lib/chgk_rating/models/recap_spec.rb +34 -34
  55. data/spec/lib/chgk_rating/models/team_spec.rb +88 -88
  56. data/spec/lib/chgk_rating/models/tournament_player_spec.rb +20 -20
  57. data/spec/lib/chgk_rating/models/tournament_spec.rb +91 -91
  58. data/spec/lib/chgk_rating/models/tournament_team_result_spec.rb +18 -18
  59. data/spec/lib/chgk_rating/models/tournament_team_spec.rb +35 -35
  60. data/spec/lib/chgk_rating/utils/snakecase_spec.rb +11 -11
  61. data/spec/lib/chgk_rating/utils/transformations_spec.rb +15 -15
  62. data/spec/lib/chgk_rating_spec.rb +4 -4
  63. data/spec/lib/ext/date_spec.rb +6 -6
  64. data/spec/lib/ext/date_time_spec.rb +10 -10
  65. data/spec/lib/ext/uri_spec.rb +6 -6
  66. data/spec/spec_helper.rb +12 -12
  67. data/spec/support/shared_examples.rb +62 -62
  68. data/spec/support/test_client.rb +5 -5
  69. data/spec/support/vcr.rb +10 -9
  70. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6fcd0eda982c479f893b2916ddd64f4c9012d1a3bee014815286508eff6a8196
4
- data.tar.gz: 1258475c6db685a690625af746f070af96169f848352988a548735c4fb11a455
3
+ metadata.gz: c1f40e4500f25b4c4fa174235cdfb13a5d5262800d7128ab412f50e85efcb2e3
4
+ data.tar.gz: 65054a1c6ec251becfbc8a5fb73a221aa36ff2841c097d921464eeebc942b11b
5
5
  SHA512:
6
- metadata.gz: ddcd9876020c92ae27395757111b3be3b762a4b782c2dfbe233a1f201101e9e8c8e61d3e32dbfe2b7c63087b75f7e70fae42a2f6c141b1b1897b1ae9c51fc11b
7
- data.tar.gz: 196d2cf44f13b07690bb52dd5fec7bb95bcd421da25309b649975bb48428414598c83272715c97297a8baf1565758a2849f1e58c296e1ded928bd10270f997ee
6
+ metadata.gz: f045d2354e6f6f35cf1486611bbe3954bf5e400914c71fa7c1a47154542aa197cf9b61a0dba0334840f318b1d02a890dc426f7a09bd444ab1715ab2e9c2f61c8
7
+ data.tar.gz: c93f31ee95abe8900dce72730fda98a18f09737fa4b29026df0d6d077d8e1692b60c3302109c06c6d35a33db1c1e17380cc9746a0cf5fa31cafce419b040c888
@@ -1,13 +1,13 @@
1
- ### Steps to reproduce
2
-
3
- ### Expected behavior
4
-
5
- Tell us what should happen
6
-
7
- ### Actual behavior
8
-
9
- Tell us what happens instead
10
-
11
- ### System configuration
12
-
1
+ ### Steps to reproduce
2
+
3
+ ### Expected behavior
4
+
5
+ Tell us what should happen
6
+
7
+ ### Actual behavior
8
+
9
+ Tell us what happens instead
10
+
11
+ ### System configuration
12
+
13
13
  **Ruby version**:
@@ -1,11 +1,11 @@
1
- ### Summary
2
-
3
- Provide a general description of the code changes in your pull
4
- request. Were there any bugs you had fixed? If so, mention them. If
5
- these bugs have open GitHub issues, be sure to tag them here as well,
6
- to keep the conversation linked together.
7
-
8
- ### Other Information
9
-
10
- If there's anything else that's important and relevant to your pull
1
+ ### Summary
2
+
3
+ Provide a general description of the code changes in your pull
4
+ request. Were there any bugs you had fixed? If so, mention them. If
5
+ these bugs have open GitHub issues, be sure to tag them here as well,
6
+ to keep the conversation linked together.
7
+
8
+ ### Other Information
9
+
10
+ If there's anything else that's important and relevant to your pull
11
11
  request, mention that information here.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.0.0 (2018-02-23)
4
+
5
+ * First stable version at last
6
+ * Make `TournamentTeam` compatible with the recent API changes
7
+ * More doc tweaks
8
+ * Fix tests compatibility with Ruby 2.5
9
+
3
10
  ## v1.0.0.rc1 (2018-02-22)
4
11
 
5
12
  * Collections can be converted to arrays or hashes
data/Gemfile CHANGED
@@ -1,7 +1,3 @@
1
- source 'http://rubygems.org'
2
-
3
- group :development do
4
- gem 'pry'
5
- end
6
-
1
+ source 'http://rubygems.org'
2
+
7
3
  gemspec
data/LICENSE CHANGED
@@ -1,22 +1,22 @@
1
- The MIT License
2
-
3
- Copyright (c) 2017 Ilya Bodrov
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
1
+ The MIT License
2
+
3
+ Copyright (c) 2017 Ilya Bodrov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
22
  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # ChgkRating
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/chgk_rating.svg)](https://badge.fury.io/rb/chgk_rating)
3
4
  [![Build Status](https://travis-ci.org/bodrovis/ChgkRating.svg?branch=master)](https://travis-ci.org/bodrovis/ChgkRating)
4
5
  [![Code Climate](https://codeclimate.com/github/bodrovis/ChgkRating/badges/gpa.svg)](https://codeclimate.com/github/bodrovis/ChgkRating)
5
6
  [![Test Coverage](https://codeclimate.com/github/bodrovis/ChgkRating/badges/coverage.svg)](https://codeclimate.com/github/bodrovis/ChgkRating/coverage)
@@ -452,7 +453,7 @@ current_name # String
452
453
  base_name # String
453
454
  position # Float
454
455
  questions_total # Integer
455
- Result # Array - contains Boolean values. Each value corresponds to a single question and
456
+ result # Array - contains Boolean values. Each value corresponds to a single question and
456
457
  # marks whether the team answered this question or not. The length of the array equals to the
457
458
  # value returned by the questions_total method
458
459
  bonus_a # Integer
data/Rakefile CHANGED
@@ -1,13 +1,13 @@
1
- require 'rake'
2
-
3
- begin
4
- require 'bundler/setup'
5
- Bundler::GemHelper.install_tasks
6
- rescue LoadError
7
- puts 'although not required, bundler is recommened for running the tests'
8
- end
9
-
10
- task :default => :spec
11
-
12
- require 'rspec/core/rake_task'
1
+ require 'rake'
2
+
3
+ begin
4
+ require 'bundler/setup'
5
+ Bundler::GemHelper.install_tasks
6
+ rescue LoadError
7
+ puts 'although not required, bundler is recommened for running the tests'
8
+ end
9
+
10
+ task :default => :spec
11
+
12
+ require 'rspec/core/rake_task'
13
13
  RSpec::Core::RakeTask.new(:spec)
data/chgk_rating.gemspec CHANGED
@@ -1,29 +1,29 @@
1
- require File.expand_path('../lib/chgk_rating/version', __FILE__)
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = 'chgk_rating'
5
- spec.version = ChgkRating::VERSION
6
- spec.authors = ['Ilya Bodrov']
7
- spec.email = ['golosizpru@gmail.com']
8
- 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'
10
- spec.homepage = 'https://github.com/bodrovis/chgk_rating'
11
- spec.license = 'MIT'
12
- spec.platform = Gem::Platform::RUBY
13
- spec.required_ruby_version = '>= 2.4.0'
14
-
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.extra_rdoc_files = ['README.md']
20
- spec.require_paths = ['lib']
21
-
22
- spec.add_dependency 'faraday', '~> 0.13'
23
- spec.add_dependency 'multi_json', '~> 1.12'
24
-
25
- spec.add_development_dependency 'rake', '~> 12.1'
26
- spec.add_development_dependency 'rspec', '~> 3.6'
27
- spec.add_development_dependency 'vcr', '~> 4.0'
28
- spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
1
+ require File.expand_path('../lib/chgk_rating/version', __FILE__)
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'chgk_rating'
5
+ spec.version = ChgkRating::VERSION
6
+ spec.authors = ['Ilya Bodrov']
7
+ spec.email = ['golosizpru@gmail.com']
8
+ 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'
10
+ spec.homepage = 'https://github.com/bodrovis/ChgkRating'
11
+ spec.license = 'MIT'
12
+ spec.platform = Gem::Platform::RUBY
13
+ spec.required_ruby_version = '>= 2.4.0'
14
+
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.extra_rdoc_files = ['README.md']
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'faraday', '~> 0.13'
23
+ spec.add_dependency 'multi_json', '~> 1.12'
24
+
25
+ spec.add_development_dependency 'rake', '~> 12.1'
26
+ spec.add_development_dependency 'rspec', '~> 3.6'
27
+ spec.add_development_dependency 'vcr', '~> 4.0'
28
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
29
29
  end
data/lib/chgk_rating.rb CHANGED
@@ -1,53 +1,52 @@
1
- require 'pry'
2
- require 'date'
3
- require 'uri'
4
- require 'faraday'
5
- require 'multi_json'
6
-
7
- require 'ext/date'
8
- require 'ext/date_time'
9
- require 'ext/uri'
10
-
11
- require 'chgk_rating/utils/transformations'
12
- require 'chgk_rating/utils/snakecase'
13
-
14
- require 'chgk_rating/version'
15
- require 'chgk_rating/error'
16
- require 'chgk_rating/connection'
17
- require 'chgk_rating/request'
18
- require 'chgk_rating/attribute_mappings'
19
-
20
- require 'chgk_rating/concerns/searching'
21
-
22
- require 'chgk_rating/chgk_object'
23
-
24
- require 'chgk_rating/models/base'
25
- require 'chgk_rating/models/tournament_team_result'
26
- require 'chgk_rating/models/tournament_player'
27
- require 'chgk_rating/models/tournament_team'
28
- require 'chgk_rating/models/rating'
29
- require 'chgk_rating/models/tournament'
30
- require 'chgk_rating/models/player'
31
- require 'chgk_rating/models/team'
32
- require 'chgk_rating/models/recap'
33
-
34
- require 'chgk_rating/collections/base'
35
- require 'chgk_rating/collections/tournament_team_results'
36
- require 'chgk_rating/collections/tournament_players'
37
- require 'chgk_rating/collections/tournament_teams'
38
- require 'chgk_rating/collections/ratings'
39
- require 'chgk_rating/collections/tournaments'
40
- require 'chgk_rating/collections/players'
41
- require 'chgk_rating/collections/teams'
42
- require 'chgk_rating/collections/recaps'
43
-
44
- require 'chgk_rating/client'
45
-
46
- module ChgkRating
47
- # Initializes a new Client object
48
- #
49
- # @return [ChgkRating::Client]
50
- def self.client
51
- @client ||= ChgkRating::Client.new
52
- end
1
+ require 'date'
2
+ require 'uri'
3
+ require 'faraday'
4
+ require 'multi_json'
5
+
6
+ require 'ext/date'
7
+ require 'ext/date_time'
8
+ require 'ext/uri'
9
+
10
+ require 'chgk_rating/utils/transformations'
11
+ require 'chgk_rating/utils/snakecase'
12
+
13
+ require 'chgk_rating/version'
14
+ require 'chgk_rating/error'
15
+ require 'chgk_rating/connection'
16
+ require 'chgk_rating/request'
17
+ require 'chgk_rating/attribute_mappings'
18
+
19
+ require 'chgk_rating/concerns/searching'
20
+
21
+ require 'chgk_rating/chgk_object'
22
+
23
+ require 'chgk_rating/models/base'
24
+ require 'chgk_rating/models/tournament_team_result'
25
+ require 'chgk_rating/models/tournament_player'
26
+ require 'chgk_rating/models/tournament_team'
27
+ require 'chgk_rating/models/rating'
28
+ require 'chgk_rating/models/tournament'
29
+ require 'chgk_rating/models/player'
30
+ require 'chgk_rating/models/team'
31
+ require 'chgk_rating/models/recap'
32
+
33
+ require 'chgk_rating/collections/base'
34
+ require 'chgk_rating/collections/tournament_team_results'
35
+ require 'chgk_rating/collections/tournament_players'
36
+ require 'chgk_rating/collections/tournament_teams'
37
+ require 'chgk_rating/collections/ratings'
38
+ require 'chgk_rating/collections/tournaments'
39
+ require 'chgk_rating/collections/players'
40
+ require 'chgk_rating/collections/teams'
41
+ require 'chgk_rating/collections/recaps'
42
+
43
+ require 'chgk_rating/client'
44
+
45
+ module ChgkRating
46
+ # Initializes a new Client object
47
+ #
48
+ # @return [ChgkRating::Client]
49
+ def self.client
50
+ @client ||= ChgkRating::Client.new
51
+ end
53
52
  end
@@ -1,138 +1,139 @@
1
- module ChgkRating
2
- module AttributeMappings
3
- extend ChgkRating::Utils::Transformations
4
-
5
- class << self
6
- def find(name)
7
- const_get name.snakecase_upcase
8
- end
9
-
10
- def generate_mappings_for(data)
11
- data.each do |const_name, raw_schemes|
12
- const_set const_name, generate_mapping_for(raw_schemes)
13
- end
14
- end
15
-
16
- private
17
-
18
- def name_from(raw_name)
19
- { raw_name: raw_name.to_s }
20
- end
21
-
22
- def parse_raw_scheme(raw_scheme)
23
- if raw_scheme.respond_to? :inject
24
- scheme_from raw_scheme
25
- else
26
- { raw_scheme => name_from(raw_scheme) }
27
- end
28
- end
29
-
30
- def scheme_from(raw_scheme)
31
- raw_scheme.inject({}) do |memo, (key, value)|
32
- memo[key] = scheme_value_from key, value
33
- memo
34
- end
35
- end
36
-
37
- def scheme_value_from(key, raw_value)
38
- if raw_value.is_a? String
39
- name_from raw_value
40
- else
41
- raw_value = [key.to_s] if raw_value[0].nil? # for cases like `rating: []`
42
- name_from(raw_value[0]).merge transformation(raw_value[1])
43
- end
44
- end
45
-
46
- def generate_mapping_for(raw_schemes)
47
- return unless raw_schemes&.any?
48
-
49
- if raw_schemes.is_a? Array
50
- raw_schemes.inject({}) do |memo, raw_scheme|
51
- memo.merge parse_raw_scheme(raw_scheme)
52
- end
53
- else
54
- parse_raw_scheme raw_schemes
55
- end.freeze
56
- end
57
- end
58
-
59
- 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]
75
- },
76
- RECAP: {
77
- season_id: 'idseason',
78
- team: ['idteam', :team_id],
79
- captain: ['captain', :player_id],
80
- players: ['players', :players_ids]
81
- },
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]
108
- },
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
- real_bonus_b: [],
120
- d_bonus_b: [],
121
- included_in_rating: ['included_in_rating', :boolean_binboolean]
122
- },
123
- :current_name,
124
- :base_name
125
- ],
126
- TEAM: [
127
- { id: 'idteam' },
128
- :name,
129
- :town,
130
- :comment
131
- ],
132
- TOURNAMENT_TEAM_RESULT: {
133
- tour: [],
134
- result: ['mask', :arrayboolean_arraystrboolean]
135
- }
136
- })
137
- end
1
+ module ChgkRating
2
+ module AttributeMappings
3
+ extend ChgkRating::Utils::Transformations
4
+
5
+ class << self
6
+ def find(name)
7
+ const_get name.snakecase_upcase
8
+ end
9
+
10
+ def generate_mappings_for(data)
11
+ data.each do |const_name, raw_schemes|
12
+ const_set const_name, generate_mapping_for(raw_schemes)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def name_from(raw_name)
19
+ { raw_name: raw_name.to_s }
20
+ end
21
+
22
+ def parse_raw_scheme(raw_scheme)
23
+ if raw_scheme.respond_to? :inject
24
+ scheme_from raw_scheme
25
+ else
26
+ { raw_scheme => name_from(raw_scheme) }
27
+ end
28
+ end
29
+
30
+ def scheme_from(raw_scheme)
31
+ raw_scheme.inject({}) do |memo, (key, value)|
32
+ memo[key] = scheme_value_from key, value
33
+ memo
34
+ end
35
+ end
36
+
37
+ def scheme_value_from(key, raw_value)
38
+ if raw_value.is_a? String
39
+ name_from raw_value
40
+ else
41
+ raw_value = [key.to_s] if raw_value[0].nil? # for cases like `rating: []`
42
+ name_from(raw_value[0]).merge transformation(raw_value[1])
43
+ end
44
+ end
45
+
46
+ def generate_mapping_for(raw_schemes)
47
+ return unless raw_schemes&.any?
48
+
49
+ if raw_schemes.is_a? Array
50
+ raw_schemes.inject({}) do |memo, raw_scheme|
51
+ memo.merge parse_raw_scheme(raw_scheme)
52
+ end
53
+ else
54
+ parse_raw_scheme raw_schemes
55
+ end.freeze
56
+ end
57
+ end
58
+
59
+ 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]
75
+ },
76
+ RECAP: {
77
+ season_id: 'idseason',
78
+ team: ['idteam', :team_id],
79
+ captain: ['captain', :player_id],
80
+ players: ['players', :players_ids]
81
+ },
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]
108
+ },
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
+ }
137
+ })
138
+ end
138
139
  end