sportdb 0.4.1 → 0.4.2
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.
- data/lib/sportdb/reader.rb +36 -20
- data/lib/sportdb/templater.rb +5 -1
- data/lib/sportdb/version.rb +1 -1
- metadata +4 -4
data/lib/sportdb/reader.rb
CHANGED
|
@@ -38,6 +38,8 @@ class Reader
|
|
|
38
38
|
# [ 'stuttgart', [ 'VfB Stuttgart' ]] ]
|
|
39
39
|
|
|
40
40
|
@known_teams = []
|
|
41
|
+
|
|
42
|
+
## todo/fix: move calc known_teams to model!!! (for reuse)
|
|
41
43
|
|
|
42
44
|
@event.teams.each_with_index do |team,index|
|
|
43
45
|
|
|
@@ -93,17 +95,30 @@ class Reader
|
|
|
93
95
|
# and return it
|
|
94
96
|
# NB: side effect - removes date from line string
|
|
95
97
|
|
|
96
|
-
# e.g. 14
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
# e.g. 2012-09-14 20:30 => YYYY-MM-DD HH:MM
|
|
99
|
+
regex_db = /\b(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2})\b/
|
|
100
|
+
|
|
101
|
+
# e.g. 14.09. 20:30 => DD.MM. HH:MM
|
|
102
|
+
regex_de = /\b(\d{2})\.(\d{2})\.\s+(\d{2}):(\d{2})\b/
|
|
103
|
+
|
|
104
|
+
if line =~ regex_db
|
|
105
|
+
value = "#{$1}-#{$2}-#{$3} #{$4}:#{$5}"
|
|
106
|
+
puts " date: >#{value}<"
|
|
107
|
+
|
|
108
|
+
## todo: lets you configure year
|
|
109
|
+
## and time zone (e.g. cet, eet, utc, etc.)
|
|
110
|
+
|
|
111
|
+
line.sub!( regex_db, '[DATE.DB]' )
|
|
112
|
+
|
|
113
|
+
return DateTime.strptime( value, '%Y-%m-%d %H:%M' )
|
|
114
|
+
elsif line =~ regex_de
|
|
100
115
|
value = "2012-#{$2}-#{$1} #{$3}:#{$4}"
|
|
101
116
|
puts " date: >#{value}<"
|
|
102
117
|
|
|
103
118
|
## todo: lets you configure year
|
|
104
119
|
## and time zone (e.g. cet, eet, utc, etc.)
|
|
105
120
|
|
|
106
|
-
line.sub!(
|
|
121
|
+
line.sub!( regex_de, '[DATE.DE]' )
|
|
107
122
|
|
|
108
123
|
return DateTime.strptime( value, '%Y-%m-%d %H:%M' )
|
|
109
124
|
else
|
|
@@ -241,25 +256,26 @@ class Reader
|
|
|
241
256
|
|
|
242
257
|
else
|
|
243
258
|
puts "parsing game (fixture) line: >#{line}<"
|
|
259
|
+
|
|
260
|
+
match_teams!( line )
|
|
261
|
+
team1_key = find_team1!( line )
|
|
262
|
+
team2_key = find_team2!( line )
|
|
263
|
+
|
|
244
264
|
date = find_date!( line )
|
|
245
265
|
score = find_score!( line )
|
|
246
266
|
|
|
247
|
-
match_teams!( line )
|
|
248
|
-
team1 = find_team1!( line )
|
|
249
|
-
team2 = find_team2!( line )
|
|
250
|
-
|
|
251
267
|
puts " line: >#{line}<"
|
|
252
268
|
|
|
253
269
|
|
|
254
270
|
### todo: cache team lookups in hash?
|
|
255
271
|
|
|
256
|
-
|
|
257
|
-
|
|
272
|
+
team1 = Team.find_by_key!( team1_key )
|
|
273
|
+
team2 = Team.find_by_key!( team2_key )
|
|
258
274
|
|
|
259
275
|
### check if games exists
|
|
260
276
|
## with this teams in this round if yes only update
|
|
261
|
-
|
|
262
|
-
@round.id,
|
|
277
|
+
game = Game.find_by_round_id_and_team1_id_and_team2_id(
|
|
278
|
+
@round.id, team1.id, team2.id
|
|
263
279
|
)
|
|
264
280
|
|
|
265
281
|
game_attribs = {
|
|
@@ -268,27 +284,27 @@ class Reader
|
|
|
268
284
|
play_at: date
|
|
269
285
|
}
|
|
270
286
|
|
|
271
|
-
if
|
|
272
|
-
puts "*** update game #{
|
|
287
|
+
if game.present?
|
|
288
|
+
puts "*** update game #{game.id}:"
|
|
273
289
|
else
|
|
274
290
|
puts "*** create game:"
|
|
275
|
-
|
|
291
|
+
game = Game.new
|
|
276
292
|
|
|
277
293
|
more_game_attribs = {
|
|
278
294
|
## NB: use round.games.count for pos
|
|
279
295
|
## lets us add games out of order if later needed
|
|
280
296
|
pos: @round.games.count+1,
|
|
281
297
|
round_id: @round.id,
|
|
282
|
-
team1_id:
|
|
283
|
-
team2_id:
|
|
298
|
+
team1_id: team1.id,
|
|
299
|
+
team2_id: team2.id
|
|
284
300
|
}
|
|
285
301
|
game_attribs = game_attribs.merge( more_game_attribs )
|
|
286
302
|
end
|
|
287
303
|
|
|
288
304
|
puts game_attribs.to_json
|
|
289
305
|
|
|
290
|
-
|
|
291
|
-
end
|
|
306
|
+
game.update_attributes!( game_attribs )
|
|
307
|
+
end
|
|
292
308
|
end # oldlines.each
|
|
293
309
|
|
|
294
310
|
@patch_rounds ||= {}
|
data/lib/sportdb/templater.rb
CHANGED
|
@@ -54,7 +54,8 @@ class Templater
|
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
args.each do |arg|
|
|
57
|
-
name = File.basename( arg, '.*' )
|
|
57
|
+
## name = File.basename( arg, '.*' )
|
|
58
|
+
name = arg
|
|
58
59
|
gen_fixtures( name )
|
|
59
60
|
end
|
|
60
61
|
|
|
@@ -69,6 +70,9 @@ class Templater
|
|
|
69
70
|
## todo: honor -o/--output option ??
|
|
70
71
|
|
|
71
72
|
dest = "#{name}.rb"
|
|
73
|
+
|
|
74
|
+
## todo: check if path (parent dirs) exits?
|
|
75
|
+
|
|
72
76
|
source = "#{SportDB.root}/templates/fixtures.rb.erb"
|
|
73
77
|
|
|
74
78
|
puts " Merging template #{source} to #{dest}..."
|
data/lib/sportdb/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sportdb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 11
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 4
|
|
9
|
-
-
|
|
10
|
-
version: 0.4.
|
|
9
|
+
- 2
|
|
10
|
+
version: 0.4.2
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Gerald Bauer
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2012-10-
|
|
18
|
+
date: 2012-10-27 00:00:00 Z
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
21
21
|
name: activerecord
|