scrap_cbf_record 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/scrap_cbf_record.rb +72 -0
- data/lib/scrap_cbf_record/active_record.rb +105 -0
- data/lib/scrap_cbf_record/active_records/base.rb +196 -0
- data/lib/scrap_cbf_record/active_records/matches.rb +80 -0
- data/lib/scrap_cbf_record/active_records/rankings.rb +70 -0
- data/lib/scrap_cbf_record/active_records/rounds.rb +60 -0
- data/lib/scrap_cbf_record/active_records/teams.rb +42 -0
- data/lib/scrap_cbf_record/config.rb +217 -0
- data/lib/scrap_cbf_record/configs/base.rb +258 -0
- data/lib/scrap_cbf_record/configs/championship.rb +97 -0
- data/lib/scrap_cbf_record/configs/match.rb +164 -0
- data/lib/scrap_cbf_record/configs/ranking.rb +152 -0
- data/lib/scrap_cbf_record/configs/round.rb +113 -0
- data/lib/scrap_cbf_record/configs/team.rb +99 -0
- data/lib/scrap_cbf_record/errors.rb +83 -0
- data/lib/scrap_cbf_record/logger.rb +20 -0
- data/lib/scrap_cbf_record/models/base.rb +16 -0
- data/lib/scrap_cbf_record/models/championship.rb +28 -0
- data/lib/scrap_cbf_record/models/concerns/active_record_relation.rb +37 -0
- data/lib/scrap_cbf_record/models/match.rb +71 -0
- data/lib/scrap_cbf_record/models/ranking.rb +58 -0
- data/lib/scrap_cbf_record/models/round.rb +54 -0
- data/lib/scrap_cbf_record/models/team.rb +22 -0
- data/lib/scrap_cbf_record/version.rb +5 -0
- metadata +170 -0
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ScrapCbfRecord
|
4
|
+
class Config
|
5
|
+
# Championship settings
|
6
|
+
class Championship < Base
|
7
|
+
class << self
|
8
|
+
# Default settings
|
9
|
+
#
|
10
|
+
# @return [Hash]
|
11
|
+
def default
|
12
|
+
{
|
13
|
+
class_name: 'Championship',
|
14
|
+
rename_attrs: {},
|
15
|
+
exclude_attrs_on_create: %i[],
|
16
|
+
exclude_attrs_on_update: %i[],
|
17
|
+
associations: {}
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
# Settings use by the system
|
22
|
+
# Not configurable
|
23
|
+
#
|
24
|
+
# @return [Hash]
|
25
|
+
def required
|
26
|
+
{ must_exclude_attrs: %i[] }
|
27
|
+
end
|
28
|
+
|
29
|
+
# Record Attributes
|
30
|
+
# It must match with ScrapCbf
|
31
|
+
#
|
32
|
+
# @return [Array]
|
33
|
+
def record_attrs
|
34
|
+
%i[
|
35
|
+
year
|
36
|
+
serie
|
37
|
+
]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
attr_reader :class_name,
|
42
|
+
:rename_attrs,
|
43
|
+
:exclude_attrs_on_create,
|
44
|
+
:exclude_attrs_on_update,
|
45
|
+
:associations
|
46
|
+
|
47
|
+
# Starts the settings with default
|
48
|
+
#
|
49
|
+
# @return [nil]
|
50
|
+
def initialize
|
51
|
+
@class_name = default_class_name
|
52
|
+
@rename_attrs = default_rename_attrs
|
53
|
+
@exclude_attrs_on_create = default_exclude_attrs_on_create
|
54
|
+
@exclude_attrs_on_update = default_exclude_attrs_on_update
|
55
|
+
@associations = default_associations
|
56
|
+
|
57
|
+
ScrapCbfRecord::Championship.config = self
|
58
|
+
|
59
|
+
super(*configs)
|
60
|
+
end
|
61
|
+
|
62
|
+
# These method receives the users settings
|
63
|
+
# Missing settings are left as default
|
64
|
+
#
|
65
|
+
# @param [config] Hash contaning the settings
|
66
|
+
# @return [nil]
|
67
|
+
def config=(config)
|
68
|
+
raise ::ArgumentError, 'config must be a Hash' unless config.is_a?(Hash)
|
69
|
+
|
70
|
+
@class_name = config[:class_name] if config[:class_name]
|
71
|
+
@rename_attrs = config[:rename_attrs] if config[:rename_attrs]
|
72
|
+
if config[:exclude_attrs_on_create]
|
73
|
+
@exclude_attrs_on_create = config[:exclude_attrs_on_create]
|
74
|
+
end
|
75
|
+
if config[:exclude_attrs_on_update]
|
76
|
+
@exclude_attrs_on_update = config[:exclude_attrs_on_update]
|
77
|
+
end
|
78
|
+
@associations = config[:associations] if config[:associations]
|
79
|
+
|
80
|
+
super(*configs)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Return the configurable settings
|
84
|
+
#
|
85
|
+
# @return [Array]
|
86
|
+
def configs
|
87
|
+
[
|
88
|
+
@class_name,
|
89
|
+
@rename_attrs,
|
90
|
+
@exclude_attrs_on_create,
|
91
|
+
@exclude_attrs_on_update,
|
92
|
+
@associations
|
93
|
+
]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ScrapCbfRecord
|
4
|
+
class Config
|
5
|
+
# Match settings
|
6
|
+
class Match < Base
|
7
|
+
class << self
|
8
|
+
# Default settings
|
9
|
+
#
|
10
|
+
# @return [Hash]
|
11
|
+
def default
|
12
|
+
{
|
13
|
+
class_name: 'Match',
|
14
|
+
rename_attrs: {},
|
15
|
+
exclude_attrs_on_create: %i[serie],
|
16
|
+
exclude_attrs_on_update: %i[serie],
|
17
|
+
associations: {
|
18
|
+
championship: {
|
19
|
+
class_name: 'Championship',
|
20
|
+
foreign_key: :championship_id
|
21
|
+
},
|
22
|
+
round: {
|
23
|
+
class_name: 'Round',
|
24
|
+
foreign_key: :round_id
|
25
|
+
},
|
26
|
+
team: {
|
27
|
+
class_name: 'Team',
|
28
|
+
foreign_key: :team_id
|
29
|
+
},
|
30
|
+
opponent: {
|
31
|
+
class_name: 'Team',
|
32
|
+
foreign_key: :opponent_id
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
# Settings use by the system
|
39
|
+
# Not configurable
|
40
|
+
#
|
41
|
+
# @return [Hash]
|
42
|
+
def required
|
43
|
+
{ must_exclude_attrs: %i[] }
|
44
|
+
end
|
45
|
+
|
46
|
+
# Record Attributes
|
47
|
+
# It must match with ScrapCbf
|
48
|
+
#
|
49
|
+
# @return [Array]
|
50
|
+
def record_attrs
|
51
|
+
%i[
|
52
|
+
championship
|
53
|
+
serie
|
54
|
+
round
|
55
|
+
team
|
56
|
+
opponent
|
57
|
+
id_match
|
58
|
+
team_score
|
59
|
+
opponent_score
|
60
|
+
updates
|
61
|
+
date
|
62
|
+
start_at
|
63
|
+
place
|
64
|
+
]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
attr_reader :class_name,
|
69
|
+
:rename_attrs,
|
70
|
+
:exclude_attrs_on_create,
|
71
|
+
:exclude_attrs_on_update,
|
72
|
+
:associations
|
73
|
+
|
74
|
+
# Starts the settings with default
|
75
|
+
#
|
76
|
+
# @return [nil
|
77
|
+
def initialize
|
78
|
+
@class_name = default_class_name
|
79
|
+
@rename_attrs = default_rename_attrs
|
80
|
+
@exclude_attrs_on_create = default_exclude_attrs_on_create
|
81
|
+
@exclude_attrs_on_update = default_exclude_attrs_on_update
|
82
|
+
@associations = default_associations
|
83
|
+
|
84
|
+
ScrapCbfRecord::Match.config = self
|
85
|
+
|
86
|
+
super(*configs)
|
87
|
+
end
|
88
|
+
|
89
|
+
# These method receives the users settings
|
90
|
+
# Missing settings are left as default
|
91
|
+
#
|
92
|
+
# @param [config] Hash contaning the settings
|
93
|
+
# @return [nil]
|
94
|
+
def config=(config)
|
95
|
+
raise ::ArgumentError, 'config must be a Hash' unless config.is_a?(Hash)
|
96
|
+
|
97
|
+
@class_name = config[:class_name] if config[:class_name]
|
98
|
+
|
99
|
+
@rename_attrs = config[:rename_attrs] if config[:rename_attrs]
|
100
|
+
|
101
|
+
if config[:exclude_attrs_on_create]
|
102
|
+
@exclude_attrs_on_create = config[:exclude_attrs_on_create]
|
103
|
+
end
|
104
|
+
|
105
|
+
if config[:exclude_attrs_on_update]
|
106
|
+
@exclude_attrs_on_update = config[:exclude_attrs_on_update]
|
107
|
+
end
|
108
|
+
|
109
|
+
@associations = config[:associations] if config[:associations]
|
110
|
+
|
111
|
+
super(*configs)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Return the configurable settings
|
115
|
+
#
|
116
|
+
# @return [Array]
|
117
|
+
def configs
|
118
|
+
[
|
119
|
+
@class_name,
|
120
|
+
@rename_attrs,
|
121
|
+
@exclude_attrs_on_create,
|
122
|
+
@exclude_attrs_on_update,
|
123
|
+
@associations
|
124
|
+
]
|
125
|
+
end
|
126
|
+
|
127
|
+
# Check if config has specific association.
|
128
|
+
#
|
129
|
+
# @return [Boolean]
|
130
|
+
def championship_associate?
|
131
|
+
return false unless associations?
|
132
|
+
|
133
|
+
@championship_associate ||= @associations.key?(:championship)
|
134
|
+
end
|
135
|
+
|
136
|
+
# Check if config has specific association.
|
137
|
+
#
|
138
|
+
# @return [Boolean]
|
139
|
+
def round_associate?
|
140
|
+
return false unless associations?
|
141
|
+
|
142
|
+
@round_associate ||= @associations.key?(:round)
|
143
|
+
end
|
144
|
+
|
145
|
+
# Check if config has specific association.
|
146
|
+
#
|
147
|
+
# @return [Boolean]
|
148
|
+
def team_associate?
|
149
|
+
return false unless associations?
|
150
|
+
|
151
|
+
@team_associate ||= @associations.key?(:team)
|
152
|
+
end
|
153
|
+
|
154
|
+
# Check if config has specific association.
|
155
|
+
#
|
156
|
+
# @return [Boolean]
|
157
|
+
def opponent_associate?
|
158
|
+
return false unless associations?
|
159
|
+
|
160
|
+
@opponent_associate ||= @associations.key?(:opponent)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ScrapCbfRecord
|
4
|
+
class Config
|
5
|
+
# Ranking settings
|
6
|
+
class Ranking < Base
|
7
|
+
class << self
|
8
|
+
# Default settings
|
9
|
+
#
|
10
|
+
# @return [Hash]
|
11
|
+
def default
|
12
|
+
{
|
13
|
+
class_name: 'Ranking',
|
14
|
+
rename_attrs: {},
|
15
|
+
exclude_attrs_on_create: %i[serie],
|
16
|
+
exclude_attrs_on_update: %i[serie],
|
17
|
+
associations: {
|
18
|
+
championship: {
|
19
|
+
class_name: 'Championship',
|
20
|
+
foreign_key: :championship_id
|
21
|
+
},
|
22
|
+
team: {
|
23
|
+
class_name: 'Team',
|
24
|
+
foreign_key: :team_id
|
25
|
+
},
|
26
|
+
next_opponent: {
|
27
|
+
class_name: 'Team',
|
28
|
+
foreign_key: :next_opponent_id
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
# Settings use by the system
|
35
|
+
# Not configurable
|
36
|
+
#
|
37
|
+
# @return [Hash]
|
38
|
+
def required
|
39
|
+
{ must_exclude_attrs: %i[] }
|
40
|
+
end
|
41
|
+
|
42
|
+
# Record Attributes
|
43
|
+
# It must match with ScrapCbf
|
44
|
+
#
|
45
|
+
# @return [Array]
|
46
|
+
def record_attrs
|
47
|
+
%i[
|
48
|
+
championship
|
49
|
+
serie
|
50
|
+
position
|
51
|
+
team
|
52
|
+
points
|
53
|
+
played
|
54
|
+
won
|
55
|
+
drawn
|
56
|
+
lost
|
57
|
+
goals_for
|
58
|
+
goals_against
|
59
|
+
goal_difference
|
60
|
+
yellow_card
|
61
|
+
red_card
|
62
|
+
advantages
|
63
|
+
form
|
64
|
+
next_opponent
|
65
|
+
]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
attr_reader :class_name,
|
70
|
+
:rename_attrs,
|
71
|
+
:exclude_attrs_on_create,
|
72
|
+
:exclude_attrs_on_update,
|
73
|
+
:associations
|
74
|
+
|
75
|
+
# Starts the settings with default
|
76
|
+
#
|
77
|
+
# @return [nil]
|
78
|
+
def initialize
|
79
|
+
@class_name = default_class_name
|
80
|
+
@rename_attrs = default_rename_attrs
|
81
|
+
@exclude_attrs_on_create = default_exclude_attrs_on_create
|
82
|
+
@exclude_attrs_on_update = default_exclude_attrs_on_update
|
83
|
+
@associations = default_associations
|
84
|
+
|
85
|
+
ScrapCbfRecord::Ranking.config = self
|
86
|
+
|
87
|
+
super(*configs)
|
88
|
+
end
|
89
|
+
|
90
|
+
# These method receives the users settings
|
91
|
+
# Missing settings are left as default
|
92
|
+
#
|
93
|
+
# @param [config] Hash contaning the settings
|
94
|
+
# @return [nil]
|
95
|
+
def config=(config)
|
96
|
+
raise ::ArgumentError, 'config must be a Hash' unless config.is_a?(Hash)
|
97
|
+
|
98
|
+
@class_name = config[:class_name] if config[:class_name]
|
99
|
+
@rename_attrs = config[:rename_attrs] if config[:rename_attrs]
|
100
|
+
if config[:exclude_attrs_on_create]
|
101
|
+
@exclude_attrs_on_create = config[:exclude_attrs_on_create]
|
102
|
+
end
|
103
|
+
if config[:exclude_attrs_on_update]
|
104
|
+
@exclude_attrs_on_update = config[:exclude_attrs_on_update]
|
105
|
+
end
|
106
|
+
@associations = config[:associations] if config[:associations]
|
107
|
+
|
108
|
+
super(*configs)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Return the configurable settings
|
112
|
+
#
|
113
|
+
# @return [Array]
|
114
|
+
def configs
|
115
|
+
[
|
116
|
+
@class_name,
|
117
|
+
@rename_attrs,
|
118
|
+
@exclude_attrs_on_create,
|
119
|
+
@exclude_attrs_on_update,
|
120
|
+
@associations
|
121
|
+
]
|
122
|
+
end
|
123
|
+
|
124
|
+
# Check if config has specific association.
|
125
|
+
#
|
126
|
+
# @return [Boolean]
|
127
|
+
def championship_associate?
|
128
|
+
return false unless associations?
|
129
|
+
|
130
|
+
@championship_associate ||= @associations.key?(:championship)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Check if config has specific association.
|
134
|
+
#
|
135
|
+
# @return [Boolean]
|
136
|
+
def team_associate?
|
137
|
+
return false unless associations?
|
138
|
+
|
139
|
+
@team_associate ||= @associations.key?(:team)
|
140
|
+
end
|
141
|
+
|
142
|
+
# Check if current config has specific setting association.
|
143
|
+
#
|
144
|
+
# @return [Boolean]
|
145
|
+
def next_opponent_associate?
|
146
|
+
return false unless associations?
|
147
|
+
|
148
|
+
@next_opponent_associate ||= @associations.key?(:next_opponent)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ScrapCbfRecord
|
4
|
+
class Config
|
5
|
+
# Round settings
|
6
|
+
class Round < Base
|
7
|
+
class << self
|
8
|
+
# Default settings
|
9
|
+
#
|
10
|
+
# @return [Hash]
|
11
|
+
def default
|
12
|
+
{
|
13
|
+
class_name: 'Round',
|
14
|
+
rename_attrs: {},
|
15
|
+
exclude_attrs_on_create: %i[serie],
|
16
|
+
exclude_attrs_on_update: %i[],
|
17
|
+
associations: {
|
18
|
+
championship: {
|
19
|
+
class_name: 'Championship',
|
20
|
+
foreign_key: :championship_id
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
# Settings use by the system
|
27
|
+
# Not configurable
|
28
|
+
#
|
29
|
+
# @return [Hash]
|
30
|
+
def required
|
31
|
+
{ must_exclude_attrs: %i[matches] }
|
32
|
+
end
|
33
|
+
|
34
|
+
# Record Attributes
|
35
|
+
# It must match with ScrapCbf
|
36
|
+
#
|
37
|
+
# @return [Array]
|
38
|
+
def record_attrs
|
39
|
+
%i[
|
40
|
+
championship
|
41
|
+
serie
|
42
|
+
number
|
43
|
+
matches
|
44
|
+
]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
attr_reader :class_name,
|
49
|
+
:rename_attrs,
|
50
|
+
:exclude_attrs_on_create,
|
51
|
+
:exclude_attrs_on_update,
|
52
|
+
:associations
|
53
|
+
|
54
|
+
# Starts the settings with default
|
55
|
+
#
|
56
|
+
# @return [nil]
|
57
|
+
def initialize
|
58
|
+
@class_name = default_class_name
|
59
|
+
@rename_attrs = default_rename_attrs
|
60
|
+
@exclude_attrs_on_create = default_exclude_attrs_on_create
|
61
|
+
@exclude_attrs_on_update = default_exclude_attrs_on_update
|
62
|
+
@associations = default_associations
|
63
|
+
|
64
|
+
ScrapCbfRecord::Round.config = self
|
65
|
+
|
66
|
+
super(*configs)
|
67
|
+
end
|
68
|
+
|
69
|
+
# These method receives the users settings
|
70
|
+
# Missing settings are left as default
|
71
|
+
#
|
72
|
+
# @param [config] Hash contaning the settings
|
73
|
+
# @return [nil]
|
74
|
+
def config=(config)
|
75
|
+
raise ::ArgumentError, 'config must be a Hash' unless config.is_a?(Hash)
|
76
|
+
|
77
|
+
@class_name = config[:class_name] if config[:class_name]
|
78
|
+
@rename_attrs = config[:rename_attrs] if config[:rename_attrs]
|
79
|
+
if config[:exclude_attrs_on_create]
|
80
|
+
@exclude_attrs_on_create = config[:exclude_attrs_on_create]
|
81
|
+
end
|
82
|
+
if config[:exclude_attrs_on_update]
|
83
|
+
@exclude_attrs_on_update = config[:exclude_attrs_on_update]
|
84
|
+
end
|
85
|
+
@associations = config[:associations] if config[:associations]
|
86
|
+
|
87
|
+
super(*configs)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Return the configurable settings
|
91
|
+
#
|
92
|
+
# @return [Array]
|
93
|
+
def configs
|
94
|
+
[
|
95
|
+
@class_name,
|
96
|
+
@rename_attrs,
|
97
|
+
@exclude_attrs_on_create,
|
98
|
+
@exclude_attrs_on_update,
|
99
|
+
@associations
|
100
|
+
]
|
101
|
+
end
|
102
|
+
|
103
|
+
# Check if config has specific association.
|
104
|
+
#
|
105
|
+
# @return [Boolean]
|
106
|
+
def championship_associate?
|
107
|
+
return false unless associations?
|
108
|
+
|
109
|
+
@championship_associate ||= @associations.key?(:championship)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|