sportdb-structs 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +2 -0
- data/Manifest.txt +1 -6
- data/README.md +3 -3
- data/Rakefile +1 -1
- data/lib/sportdb/structs/config.rb +39 -39
- data/lib/sportdb/structs/goal_parser_csv.rb +28 -28
- data/lib/sportdb/structs/match_parser_csv.rb +1 -1
- data/lib/sportdb/structs/match_status_parser.rb +90 -90
- data/lib/sportdb/structs/name_helper.rb +87 -87
- data/lib/sportdb/structs/structs/country.rb +28 -1
- data/lib/sportdb/structs/structs/goal.rb +231 -231
- data/lib/sportdb/structs/structs/ground.rb +78 -0
- data/lib/sportdb/structs/structs/group.rb +11 -3
- data/lib/sportdb/structs/structs/league.rb +2 -5
- data/lib/sportdb/structs/structs/match.rb +30 -29
- data/lib/sportdb/structs/structs/round.rb +14 -1
- data/lib/sportdb/structs/structs/standings.rb +271 -271
- data/lib/sportdb/structs/structs/team.rb +49 -48
- data/lib/sportdb/structs/structs/team_usage.rb +84 -84
- data/lib/sportdb/structs/version.rb +4 -4
- data/lib/sportdb/structs.rb +39 -0
- metadata +10 -16
- data/test/helper.rb +0 -13
- data/test/test_clubs.rb +0 -38
- data/test/test_csv_reader.rb +0 -30
- data/test/test_match.rb +0 -30
- data/test/test_match_status_parser.rb +0 -57
- data/test/test_name_helper.rb +0 -65
@@ -1,231 +1,231 @@
|
|
1
|
-
|
2
|
-
module Sports
|
3
|
-
|
4
|
-
|
5
|
-
## "free-standing" goal event - for import/export in separate event / goal datafiles
|
6
|
-
## returned by CsvGoalParser and others
|
7
|
-
class GoalEvent
|
8
|
-
|
9
|
-
def self.build( row ) ## rename to parse or such - why? why not?
|
10
|
-
|
11
|
-
## split match_id
|
12
|
-
team_str, more_str = row['Match'].split( '|' )
|
13
|
-
team1_str, team2_str = team_str.split( ' - ' )
|
14
|
-
|
15
|
-
more_str = more_str.strip
|
16
|
-
team1_str = team1_str.strip
|
17
|
-
team2_str = team2_str.strip
|
18
|
-
|
19
|
-
# check if more_str is a date otherwise assume round
|
20
|
-
date_fmt = if more_str =~ /^[A-Z]{3} [0-9]{1,2}$/i ## Apr 4
|
21
|
-
'%b %d'
|
22
|
-
elsif more_str =~ /^[A-Z]{3} [0-9]{1,2} [0-9]{4}$/i ## Apr 4 2019
|
23
|
-
'%b %d %Y'
|
24
|
-
else
|
25
|
-
nil
|
26
|
-
end
|
27
|
-
|
28
|
-
if date_fmt
|
29
|
-
date = Date.strptime( more_str, date_fmt )
|
30
|
-
round = nil
|
31
|
-
else
|
32
|
-
date = nil
|
33
|
-
round = more_str
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
values = row['Score'].split('-')
|
38
|
-
values = values.map { |value| value.strip }
|
39
|
-
score1 = values[0].to_i
|
40
|
-
score2 = values[1].to_i
|
41
|
-
|
42
|
-
minute = nil
|
43
|
-
offset = nil
|
44
|
-
if m=%r{([0-9]+)
|
45
|
-
(?:[ ]+
|
46
|
-
\+([0-9]+)
|
47
|
-
)?
|
48
|
-
['.]
|
49
|
-
$}x.match( row['Minute'])
|
50
|
-
minute = m[1].to_i
|
51
|
-
offset = m[2] ? m[2].to_i : nil
|
52
|
-
else
|
53
|
-
puts "!! ERROR - unsupported minute (goal) format >#{row['Minute']}<"
|
54
|
-
exit 1
|
55
|
-
end
|
56
|
-
|
57
|
-
attributes = {
|
58
|
-
team1: team1_str,
|
59
|
-
team2: team2_str,
|
60
|
-
date: date,
|
61
|
-
round: round,
|
62
|
-
score1: score1,
|
63
|
-
score2: score2,
|
64
|
-
minute: minute,
|
65
|
-
offset: offset,
|
66
|
-
player: row['Player'],
|
67
|
-
owngoal: ['(og)', '(o.g.)'].include?( row['Extra']),
|
68
|
-
penalty: ['(pen)', '(pen.)'].include?( row['Extra']),
|
69
|
-
notes: (row['Notes'].nil? || row['Notes'].empty?) ? nil : row['Notes']
|
70
|
-
}
|
71
|
-
|
72
|
-
new( **attributes )
|
73
|
-
end
|
74
|
-
|
75
|
-
|
76
|
-
## match id
|
77
|
-
attr_reader :team1,
|
78
|
-
:team2,
|
79
|
-
:round, ## optional
|
80
|
-
:date ## optional
|
81
|
-
|
82
|
-
## main attributes
|
83
|
-
attr_reader :score1,
|
84
|
-
:score2,
|
85
|
-
:player,
|
86
|
-
:minute,
|
87
|
-
:offset,
|
88
|
-
:owngoal,
|
89
|
-
:penalty,
|
90
|
-
:notes
|
91
|
-
|
92
|
-
|
93
|
-
## todo/check: or just use match.hash or such if match mapping known - why? why not?
|
94
|
-
def match_id
|
95
|
-
if round
|
96
|
-
"#{@team1} - #{@team2} | #{@round}"
|
97
|
-
else
|
98
|
-
"#{@team1} - #{@team2} | #{@date}"
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
def owngoal?() @owngoal==true; end
|
104
|
-
def penalty?() @penalty==true; end
|
105
|
-
|
106
|
-
def initialize( team1:,
|
107
|
-
team2:,
|
108
|
-
round: nil,
|
109
|
-
date: nil,
|
110
|
-
score1:,
|
111
|
-
score2:,
|
112
|
-
player:,
|
113
|
-
minute:,
|
114
|
-
offset: nil,
|
115
|
-
owngoal: false,
|
116
|
-
penalty: false,
|
117
|
-
notes: nil
|
118
|
-
)
|
119
|
-
@team1 = team1
|
120
|
-
@team2 = team2
|
121
|
-
@round = round
|
122
|
-
@date = date
|
123
|
-
|
124
|
-
@score1 = score1
|
125
|
-
@score2 = score2
|
126
|
-
@player = player
|
127
|
-
@minute = minute
|
128
|
-
@offset = offset
|
129
|
-
@owngoal = owngoal
|
130
|
-
@penalty = penalty
|
131
|
-
@notes = notes
|
132
|
-
end
|
133
|
-
|
134
|
-
|
135
|
-
## note: lets you use normalize teams or such acts like a Match struct
|
136
|
-
def update( **kwargs )
|
137
|
-
## todo/fix: use team1_name, team2_name or similar - for compat with db activerecord version? why? why not?
|
138
|
-
@team1 = kwargs[:team1] if kwargs.has_key? :team1
|
139
|
-
@team2 = kwargs[:team2] if kwargs.has_key? :team2
|
140
|
-
end
|
141
|
-
end # class GoalEvent
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
class Goal ### nested (non-freestanding) inside match (match is parent)
|
147
|
-
def self.build( events ) ## check/todo - rename to build_from_event/row or such - why? why not?
|
148
|
-
## build an array of goal structs from (csv) recs
|
149
|
-
recs = []
|
150
|
-
|
151
|
-
last_score1 = 0
|
152
|
-
last_score2 = 0
|
153
|
-
|
154
|
-
events.each do |event|
|
155
|
-
|
156
|
-
if last_score1+1 == event.score1 && last_score2 == event.score2
|
157
|
-
team = 1
|
158
|
-
elsif last_score2+1 == event.score2 && last_score1 == event.score1
|
159
|
-
team = 2
|
160
|
-
else
|
161
|
-
puts "!! ERROR - unexpected score advance (one goal at a time expected):"
|
162
|
-
puts " #{last_score1}-#{last_score2}=> #{event.score1}-#{event.score2}"
|
163
|
-
exit 1
|
164
|
-
end
|
165
|
-
|
166
|
-
last_score1 = event.score1
|
167
|
-
last_score2 = event.score2
|
168
|
-
|
169
|
-
|
170
|
-
attributes = {
|
171
|
-
score1: event.score1,
|
172
|
-
score2: event.score2,
|
173
|
-
team: team,
|
174
|
-
minute: event.minute,
|
175
|
-
offset: event.offset,
|
176
|
-
player: event.player,
|
177
|
-
owngoal: event.owngoal,
|
178
|
-
penalty: event.penalty,
|
179
|
-
notes: event.notes
|
180
|
-
}
|
181
|
-
|
182
|
-
recs << Goal.new( **attributes )
|
183
|
-
end
|
184
|
-
|
185
|
-
recs
|
186
|
-
end
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
attr_reader :score1,
|
191
|
-
:score2,
|
192
|
-
:team,
|
193
|
-
:player,
|
194
|
-
:minute,
|
195
|
-
:offset,
|
196
|
-
:owngoal,
|
197
|
-
:penalty,
|
198
|
-
:notes
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
def owngoal?() @owngoal==true; end
|
203
|
-
def penalty?() @penalty==true; end
|
204
|
-
def team1?() @team == 1; end
|
205
|
-
def team2?() @team == 2; end
|
206
|
-
|
207
|
-
def initialize( score1:,
|
208
|
-
score2:,
|
209
|
-
team:,
|
210
|
-
player:,
|
211
|
-
minute:,
|
212
|
-
offset: nil,
|
213
|
-
owngoal: false,
|
214
|
-
penalty: false,
|
215
|
-
notes: nil
|
216
|
-
)
|
217
|
-
@score1 = score1
|
218
|
-
@score2 = score2
|
219
|
-
@team = team # 1 or 2
|
220
|
-
@player = player
|
221
|
-
@minute = minute
|
222
|
-
@offset = offset
|
223
|
-
@owngoal = owngoal
|
224
|
-
@penalty = penalty
|
225
|
-
@notes = notes
|
226
|
-
end
|
227
|
-
end # class Goal
|
228
|
-
|
229
|
-
|
230
|
-
end # module Sports
|
231
|
-
|
1
|
+
|
2
|
+
module Sports
|
3
|
+
|
4
|
+
|
5
|
+
## "free-standing" goal event - for import/export in separate event / goal datafiles
|
6
|
+
## returned by CsvGoalParser and others
|
7
|
+
class GoalEvent
|
8
|
+
|
9
|
+
def self.build( row ) ## rename to parse or such - why? why not?
|
10
|
+
|
11
|
+
## split match_id
|
12
|
+
team_str, more_str = row['Match'].split( '|' )
|
13
|
+
team1_str, team2_str = team_str.split( ' - ' )
|
14
|
+
|
15
|
+
more_str = more_str.strip
|
16
|
+
team1_str = team1_str.strip
|
17
|
+
team2_str = team2_str.strip
|
18
|
+
|
19
|
+
# check if more_str is a date otherwise assume round
|
20
|
+
date_fmt = if more_str =~ /^[A-Z]{3} [0-9]{1,2}$/i ## Apr 4
|
21
|
+
'%b %d'
|
22
|
+
elsif more_str =~ /^[A-Z]{3} [0-9]{1,2} [0-9]{4}$/i ## Apr 4 2019
|
23
|
+
'%b %d %Y'
|
24
|
+
else
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
if date_fmt
|
29
|
+
date = Date.strptime( more_str, date_fmt )
|
30
|
+
round = nil
|
31
|
+
else
|
32
|
+
date = nil
|
33
|
+
round = more_str
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
values = row['Score'].split('-')
|
38
|
+
values = values.map { |value| value.strip }
|
39
|
+
score1 = values[0].to_i
|
40
|
+
score2 = values[1].to_i
|
41
|
+
|
42
|
+
minute = nil
|
43
|
+
offset = nil
|
44
|
+
if m=%r{([0-9]+)
|
45
|
+
(?:[ ]+
|
46
|
+
\+([0-9]+)
|
47
|
+
)?
|
48
|
+
['.]
|
49
|
+
$}x.match( row['Minute'])
|
50
|
+
minute = m[1].to_i
|
51
|
+
offset = m[2] ? m[2].to_i : nil
|
52
|
+
else
|
53
|
+
puts "!! ERROR - unsupported minute (goal) format >#{row['Minute']}<"
|
54
|
+
exit 1
|
55
|
+
end
|
56
|
+
|
57
|
+
attributes = {
|
58
|
+
team1: team1_str,
|
59
|
+
team2: team2_str,
|
60
|
+
date: date,
|
61
|
+
round: round,
|
62
|
+
score1: score1,
|
63
|
+
score2: score2,
|
64
|
+
minute: minute,
|
65
|
+
offset: offset,
|
66
|
+
player: row['Player'],
|
67
|
+
owngoal: ['(og)', '(o.g.)'].include?( row['Extra']),
|
68
|
+
penalty: ['(pen)', '(pen.)'].include?( row['Extra']),
|
69
|
+
notes: (row['Notes'].nil? || row['Notes'].empty?) ? nil : row['Notes']
|
70
|
+
}
|
71
|
+
|
72
|
+
new( **attributes )
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
## match id
|
77
|
+
attr_reader :team1,
|
78
|
+
:team2,
|
79
|
+
:round, ## optional
|
80
|
+
:date ## optional
|
81
|
+
|
82
|
+
## main attributes
|
83
|
+
attr_reader :score1,
|
84
|
+
:score2,
|
85
|
+
:player,
|
86
|
+
:minute,
|
87
|
+
:offset,
|
88
|
+
:owngoal,
|
89
|
+
:penalty,
|
90
|
+
:notes
|
91
|
+
|
92
|
+
|
93
|
+
## todo/check: or just use match.hash or such if match mapping known - why? why not?
|
94
|
+
def match_id
|
95
|
+
if round
|
96
|
+
"#{@team1} - #{@team2} | #{@round}"
|
97
|
+
else
|
98
|
+
"#{@team1} - #{@team2} | #{@date}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
def owngoal?() @owngoal==true; end
|
104
|
+
def penalty?() @penalty==true; end
|
105
|
+
|
106
|
+
def initialize( team1:,
|
107
|
+
team2:,
|
108
|
+
round: nil,
|
109
|
+
date: nil,
|
110
|
+
score1:,
|
111
|
+
score2:,
|
112
|
+
player:,
|
113
|
+
minute:,
|
114
|
+
offset: nil,
|
115
|
+
owngoal: false,
|
116
|
+
penalty: false,
|
117
|
+
notes: nil
|
118
|
+
)
|
119
|
+
@team1 = team1
|
120
|
+
@team2 = team2
|
121
|
+
@round = round
|
122
|
+
@date = date
|
123
|
+
|
124
|
+
@score1 = score1
|
125
|
+
@score2 = score2
|
126
|
+
@player = player
|
127
|
+
@minute = minute
|
128
|
+
@offset = offset
|
129
|
+
@owngoal = owngoal
|
130
|
+
@penalty = penalty
|
131
|
+
@notes = notes
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
## note: lets you use normalize teams or such acts like a Match struct
|
136
|
+
def update( **kwargs )
|
137
|
+
## todo/fix: use team1_name, team2_name or similar - for compat with db activerecord version? why? why not?
|
138
|
+
@team1 = kwargs[:team1] if kwargs.has_key? :team1
|
139
|
+
@team2 = kwargs[:team2] if kwargs.has_key? :team2
|
140
|
+
end
|
141
|
+
end # class GoalEvent
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
class Goal ### nested (non-freestanding) inside match (match is parent)
|
147
|
+
def self.build( events ) ## check/todo - rename to build_from_event/row or such - why? why not?
|
148
|
+
## build an array of goal structs from (csv) recs
|
149
|
+
recs = []
|
150
|
+
|
151
|
+
last_score1 = 0
|
152
|
+
last_score2 = 0
|
153
|
+
|
154
|
+
events.each do |event|
|
155
|
+
|
156
|
+
if last_score1+1 == event.score1 && last_score2 == event.score2
|
157
|
+
team = 1
|
158
|
+
elsif last_score2+1 == event.score2 && last_score1 == event.score1
|
159
|
+
team = 2
|
160
|
+
else
|
161
|
+
puts "!! ERROR - unexpected score advance (one goal at a time expected):"
|
162
|
+
puts " #{last_score1}-#{last_score2}=> #{event.score1}-#{event.score2}"
|
163
|
+
exit 1
|
164
|
+
end
|
165
|
+
|
166
|
+
last_score1 = event.score1
|
167
|
+
last_score2 = event.score2
|
168
|
+
|
169
|
+
|
170
|
+
attributes = {
|
171
|
+
score1: event.score1,
|
172
|
+
score2: event.score2,
|
173
|
+
team: team,
|
174
|
+
minute: event.minute,
|
175
|
+
offset: event.offset,
|
176
|
+
player: event.player,
|
177
|
+
owngoal: event.owngoal,
|
178
|
+
penalty: event.penalty,
|
179
|
+
notes: event.notes
|
180
|
+
}
|
181
|
+
|
182
|
+
recs << Goal.new( **attributes )
|
183
|
+
end
|
184
|
+
|
185
|
+
recs
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
attr_reader :score1,
|
191
|
+
:score2,
|
192
|
+
:team,
|
193
|
+
:player,
|
194
|
+
:minute,
|
195
|
+
:offset,
|
196
|
+
:owngoal,
|
197
|
+
:penalty,
|
198
|
+
:notes
|
199
|
+
|
200
|
+
|
201
|
+
|
202
|
+
def owngoal?() @owngoal==true; end
|
203
|
+
def penalty?() @penalty==true; end
|
204
|
+
def team1?() @team == 1; end
|
205
|
+
def team2?() @team == 2; end
|
206
|
+
|
207
|
+
def initialize( score1:,
|
208
|
+
score2:,
|
209
|
+
team:,
|
210
|
+
player:,
|
211
|
+
minute:,
|
212
|
+
offset: nil,
|
213
|
+
owngoal: false,
|
214
|
+
penalty: false,
|
215
|
+
notes: nil
|
216
|
+
)
|
217
|
+
@score1 = score1
|
218
|
+
@score2 = score2
|
219
|
+
@team = team # 1 or 2
|
220
|
+
@player = player
|
221
|
+
@minute = minute
|
222
|
+
@offset = offset
|
223
|
+
@owngoal = owngoal
|
224
|
+
@penalty = penalty
|
225
|
+
@notes = notes
|
226
|
+
end
|
227
|
+
end # class Goal
|
228
|
+
|
229
|
+
|
230
|
+
end # module Sports
|
231
|
+
|
@@ -0,0 +1,78 @@
|
|
1
|
+
##
|
2
|
+
# based on teams/clubs
|
3
|
+
#
|
4
|
+
|
5
|
+
|
6
|
+
module Sports
|
7
|
+
|
8
|
+
|
9
|
+
class Ground
|
10
|
+
## todo: use just names for alt_names - why? why not?
|
11
|
+
attr_accessor :key, :name, :alt_names,
|
12
|
+
:year, :year_end, ## todo/fix: change year to start_year and end_year/year_end to end_year (like in season)!!!
|
13
|
+
:country,
|
14
|
+
:city, :district,
|
15
|
+
:geos,
|
16
|
+
:address
|
17
|
+
|
18
|
+
def names
|
19
|
+
## todo/check: add alt_names_auto too? - why? why not?
|
20
|
+
[@name] + @alt_names
|
21
|
+
end ## all names
|
22
|
+
|
23
|
+
def key
|
24
|
+
## note: auto-generate key "on-the-fly" if missing for now - why? why not?
|
25
|
+
## note: quick hack - auto-generate key, that is, remove all non-ascii chars and downcase
|
26
|
+
## fix update - allow numbers (0-9)
|
27
|
+
## add dash(-) plus parens () too!! for (-1999) or (1999-2011) or such
|
28
|
+
## add umlauts too for now - plus add more later!!!
|
29
|
+
##
|
30
|
+
## fix- add more (all) diacritics!!!
|
31
|
+
## GÍ Gøta (1926-2008)
|
32
|
+
## FC Suðuroy
|
33
|
+
## fix - remove dash(-) if not followed or preceded by year (four digits)!!!
|
34
|
+
##
|
35
|
+
## use new (autogen)key rule
|
36
|
+
## - 1st unaccent, 2nd downcase, 3rd remove space et al
|
37
|
+
## use keygen or autokey function or such - why? why not?
|
38
|
+
|
39
|
+
## note: ALWAYS auto-add city to key to make unique!!!!!
|
40
|
+
## e.g. Red Bull Arena, Allianz Arena etc.
|
41
|
+
|
42
|
+
@key ||= begin
|
43
|
+
fst = unaccent( @name ).downcase.gsub( /[^a-z0-9()-]/, '' )
|
44
|
+
snd = unaccent( city ).downcase.gsub( /[^a-z0-9]/, '' )
|
45
|
+
trd = country.key
|
46
|
+
## use / as separator (or @ or ??) - why? why not?
|
47
|
+
fst + '_' + snd + '_' + trd
|
48
|
+
end
|
49
|
+
@key
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
## todo/check
|
54
|
+
## check event_ifno - for start_date, end_date ??
|
55
|
+
## use same naming convention here too (start_year/end_year)
|
56
|
+
def historic?() @year_end ? true : false; end
|
57
|
+
alias_method :past?, :historic?
|
58
|
+
|
59
|
+
|
60
|
+
def initialize( **kwargs )
|
61
|
+
@alt_names = []
|
62
|
+
|
63
|
+
update( **kwargs ) unless kwargs.empty?
|
64
|
+
end
|
65
|
+
|
66
|
+
def update( **kwargs )
|
67
|
+
@key = kwargs[:key] if kwargs.has_key?( :key )
|
68
|
+
@name = kwargs[:name] if kwargs.has_key?( :name )
|
69
|
+
@alt_names = kwargs[:alt_names] if kwargs.has_key?( :alt_names )
|
70
|
+
|
71
|
+
@city = kwargs[:city] if kwargs.has_key?( :city )
|
72
|
+
## todo/fix: use city struct - why? why not?
|
73
|
+
## todo/fix: add country too or report unused keywords / attributes - why? why not?
|
74
|
+
|
75
|
+
self ## note - MUST return self for chaining
|
76
|
+
end
|
77
|
+
end # class Ground
|
78
|
+
end # module Sports
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Sports
|
2
2
|
|
3
|
-
|
3
|
+
class Group
|
4
4
|
attr_reader :key, :name, :teams
|
5
5
|
|
6
6
|
def initialize( key: nil,
|
@@ -10,7 +10,15 @@ module Sports
|
|
10
10
|
@name = name
|
11
11
|
@teams = teams
|
12
12
|
end
|
13
|
-
end # class Group
|
14
13
|
|
14
|
+
def pretty_print( printer )
|
15
|
+
## todo/check - how to display/format key - use () or not - why? why not?
|
16
|
+
buf = String.new
|
17
|
+
buf << "<Group: #{@key ? @key : '?'} - #{@name} "
|
18
|
+
buf << @teams.pretty_print_inspect
|
19
|
+
buf << ">"
|
20
|
+
|
21
|
+
printer.text( buf )
|
22
|
+
end
|
23
|
+
end # class Group
|
15
24
|
end # module Sports
|
16
|
-
|
@@ -6,16 +6,13 @@ class League
|
|
6
6
|
attr_reader :key, :name, :country, :intl
|
7
7
|
attr_accessor :alt_names
|
8
8
|
|
9
|
-
## special import only attribs
|
10
|
-
attr_accessor :alt_names_auto ## auto-generated alt names
|
11
9
|
|
12
|
-
def initialize( key:, name:, alt_names: [],
|
10
|
+
def initialize( key:, name:, alt_names: [],
|
13
11
|
country: nil, intl: false, clubs: true )
|
14
12
|
@key = key
|
15
13
|
@name = name
|
16
14
|
@alt_names = alt_names
|
17
|
-
|
18
|
-
|
15
|
+
|
19
16
|
@country = country
|
20
17
|
@intl = intl
|
21
18
|
@clubs = clubs
|
@@ -21,8 +21,8 @@ class Match
|
|
21
21
|
:conf1, :conf2, ## special case for mls e.g. conference1, conference2 (e.g. west, east, central)
|
22
22
|
:country1, :country2, ## special case for champions league etc. - uses FIFA country code
|
23
23
|
:comments,
|
24
|
-
:league ## (optinal) added as text for now (use struct?)
|
25
|
-
|
24
|
+
:league, ## (optinal) added as text for now (use struct?)
|
25
|
+
:ground ## (optional) add as text line for now (incl. city, timezone etc.)
|
26
26
|
|
27
27
|
attr_accessor :goals ## todo/fix: make goals like all other attribs!!
|
28
28
|
|
@@ -34,33 +34,34 @@ class Match
|
|
34
34
|
@score1agg = @score2agg = nil ## full time (all legs) aggregated
|
35
35
|
|
36
36
|
|
37
|
-
update( kwargs ) unless kwargs.empty?
|
37
|
+
update( **kwargs ) unless kwargs.empty?
|
38
38
|
end
|
39
39
|
|
40
40
|
def update( **kwargs )
|
41
41
|
## note: check with has_key? because value might be nil!!!
|
42
|
-
@date = kwargs[:date] if kwargs.has_key? :date
|
43
|
-
@time = kwargs[:time] if kwargs.has_key? :time
|
42
|
+
@date = kwargs[:date] if kwargs.has_key?( :date )
|
43
|
+
@time = kwargs[:time] if kwargs.has_key?( :time )
|
44
44
|
|
45
45
|
## todo/fix: use team1_name, team2_name or similar - for compat with db activerecord version? why? why not?
|
46
|
-
@team1 = kwargs[:team1] if kwargs.has_key? :team1
|
47
|
-
@team2 = kwargs[:team2] if kwargs.has_key? :team2
|
46
|
+
@team1 = kwargs[:team1] if kwargs.has_key?( :team1 )
|
47
|
+
@team2 = kwargs[:team2] if kwargs.has_key?( :team2 )
|
48
48
|
|
49
|
-
@conf1 = kwargs[:conf1] if kwargs.has_key? :conf1
|
50
|
-
@conf2 = kwargs[:conf2] if kwargs.has_key? :conf2
|
51
|
-
@country1 = kwargs[:country1] if kwargs.has_key? :country1
|
52
|
-
@country2 = kwargs[:country2] if kwargs.has_key? :country2
|
49
|
+
@conf1 = kwargs[:conf1] if kwargs.has_key?( :conf1 )
|
50
|
+
@conf2 = kwargs[:conf2] if kwargs.has_key?( :conf2 )
|
51
|
+
@country1 = kwargs[:country1] if kwargs.has_key?( :country1 )
|
52
|
+
@country2 = kwargs[:country2] if kwargs.has_key?( :country2 )
|
53
53
|
|
54
54
|
## note: round is a string!!! e.g. '1', '2' for matchday or 'Final', 'Semi-final', etc.
|
55
55
|
## todo: use to_s - why? why not?
|
56
|
-
@round = kwargs[:round] if kwargs.has_key? :round
|
57
|
-
@stage = kwargs[:stage] if kwargs.has_key? :stage
|
58
|
-
@leg = kwargs[:leg] if kwargs.has_key? :leg
|
59
|
-
@group = kwargs[:group] if kwargs.has_key? :group
|
60
|
-
@status = kwargs[:status] if kwargs.has_key? :status
|
61
|
-
@comments = kwargs[:comments] if kwargs.has_key? :comments
|
56
|
+
@round = kwargs[:round] if kwargs.has_key?( :round )
|
57
|
+
@stage = kwargs[:stage] if kwargs.has_key?( :stage )
|
58
|
+
@leg = kwargs[:leg] if kwargs.has_key?( :leg )
|
59
|
+
@group = kwargs[:group] if kwargs.has_key?( :group )
|
60
|
+
@status = kwargs[:status] if kwargs.has_key?( :status )
|
61
|
+
@comments = kwargs[:comments] if kwargs.has_key?( :comments )
|
62
62
|
|
63
|
-
@league = kwargs[:league] if kwargs.has_key? :league
|
63
|
+
@league = kwargs[:league] if kwargs.has_key?( :league )
|
64
|
+
@ground = kwargs[:ground] if kwargs.has_key?( :ground )
|
64
65
|
|
65
66
|
|
66
67
|
if kwargs.has_key?( :score ) ## check all-in-one score struct for convenience!!!
|
@@ -91,17 +92,17 @@ class Match
|
|
91
92
|
## @score2agg = score.score2agg
|
92
93
|
end
|
93
94
|
else
|
94
|
-
@score1 = kwargs[:score1] if kwargs.has_key? :score1
|
95
|
-
@score1i = kwargs[:score1i] if kwargs.has_key? :score1i
|
96
|
-
@score1et = kwargs[:score1et] if kwargs.has_key? :score1et
|
97
|
-
@score1p = kwargs[:score1p] if kwargs.has_key? :score1p
|
98
|
-
@score1agg = kwargs[:score1agg] if kwargs.has_key? :score1agg
|
99
|
-
|
100
|
-
@score2 = kwargs[:score2] if kwargs.has_key? :score2
|
101
|
-
@score2i = kwargs[:score2i] if kwargs.has_key? :score2i
|
102
|
-
@score2et = kwargs[:score2et] if kwargs.has_key? :score2et
|
103
|
-
@score2p = kwargs[:score2p] if kwargs.has_key? :score2p
|
104
|
-
@score2agg = kwargs[:score2agg] if kwargs.has_key? :score2agg
|
95
|
+
@score1 = kwargs[:score1] if kwargs.has_key?( :score1 )
|
96
|
+
@score1i = kwargs[:score1i] if kwargs.has_key?( :score1i )
|
97
|
+
@score1et = kwargs[:score1et] if kwargs.has_key?( :score1et )
|
98
|
+
@score1p = kwargs[:score1p] if kwargs.has_key?( :score1p )
|
99
|
+
@score1agg = kwargs[:score1agg] if kwargs.has_key?( :score1agg )
|
100
|
+
|
101
|
+
@score2 = kwargs[:score2] if kwargs.has_key?( :score2 )
|
102
|
+
@score2i = kwargs[:score2i] if kwargs.has_key?( :score2i )
|
103
|
+
@score2et = kwargs[:score2et] if kwargs.has_key?( :score2et )
|
104
|
+
@score2p = kwargs[:score2p] if kwargs.has_key?( :score2p )
|
105
|
+
@score2agg = kwargs[:score2agg] if kwargs.has_key?( :score2agg )
|
105
106
|
|
106
107
|
## note: (always) (auto-)convert scores to integers
|
107
108
|
@score1 = @score1.to_i if @score1
|