sportdb 1.6.16 → 1.6.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -124,7 +124,10 @@ module SportDB
124
124
 
125
125
  def self.read( ary, include_path )
126
126
  reader = Reader.new( include_path )
127
- reader.load( ary )
127
+ ## todo: check kind_of?( Array ) or kind_of?(String) to support array or string
128
+ ary.each do |name|
129
+ reader.load( name )
130
+ end
128
131
  end
129
132
 
130
133
 
@@ -34,139 +34,81 @@ class Reader
34
34
  @include_path = include_path
35
35
  end
36
36
 
37
- def load_setup( setup )
38
- ary = load_fixture_setup( setup )
39
- load( ary )
40
- end # method load_setup
41
-
42
-
43
- ## fix/todo: rename ??
44
- def load_fixture_setup( name )
45
-
46
- ## todo/fix: cleanup quick and dirty code
47
-
37
+ def load_setup( name )
48
38
  path = "#{include_path}/#{name}.yml"
49
39
 
50
40
  logger.info "parsing data '#{name}' (#{path})..."
51
41
 
52
- text = File.read_utf8( path )
53
-
54
- hash = YAML.load( text )
55
-
56
- ### build up array for fixtures from hash
57
-
58
- ary = []
59
-
60
- hash.each do |key_wild, value_wild|
61
- key = key_wild.to_s.strip
62
-
63
- logger.debug "yaml key:#{key_wild.class.name} >>#{key}<<, value:#{value_wild.class.name} >>#{value_wild}<<"
64
-
65
- if value_wild.kind_of?( String ) # assume non-event data
66
- ary << value_wild
67
- elsif value_wild.kind_of?( Array ) # assume non_event data as array of strings
68
- ary = ary + value_wild
69
- elsif value_wild.kind_of?( Hash ) # assume event data
70
-
71
- value_wild.each do |event_key, event_values|
72
- # e.g.
73
- # at.2012/13: at/2012_13/bl, at/2012_13/bl2
74
- # becomes
75
- # [ 'at.2012/13', 'at/2012_13/bl', 'at/2012_13/bl2' ]
76
- ary << ( [ event_key.to_s ] + event_values.split(',') )
77
- end
78
-
79
- else
80
- logger.error "unknow fixture type in setup (yaml key:#{key_wild.class.name} >>#{key}<<, value:#{value_wild.class.name} >>#{value_wild}<<); skipping"
81
- end
82
-
42
+ reader = FixtureReader.new( path )
43
+
44
+ reader.each do |fixture_name|
45
+ load( fixture_name )
83
46
  end
84
-
85
- logger.debug "fixture setup:"
86
- logger.debug ary.to_json
87
-
88
- ary
89
-
90
- end # load_fixture_setup
47
+ end # method load_setup
91
48
 
92
49
 
93
- def load( ary ) # convenience helper for all-in-one reader
94
-
95
- logger.debug "enter load(include_path=>>#{include_path}<<):"
96
- logger.debug ary.to_json
97
-
98
- ary.each do |rec|
99
- if rec.kind_of?( String )
100
- ## assume single fixture name
101
- name = rec
102
-
103
- if name =~ /^circuits/ # e.g. circuits.txt in formula1.db
104
- load_tracks( name )
105
- elsif name =~ /^drivers/ # e.g. drivers.txt in formula1.db
106
- load_persons( name )
107
- elsif name =~ /^teams/ # e.g. teams.txt in formula1.db
108
- load_teams( name )
109
- elsif name =~ /\/races/ # e.g. 2013/races.txt in formula1.db
110
- load_races( name )
111
- elsif name =~ /\/squads/ || name =~ /\/rosters/ # e.g. 2013/squads.txt in formula1.db
112
- load_rosters( name )
113
- elsif name =~ /\/([0-9]{2})-/
114
- race_pos = $1.to_i
115
- # NB: assume @event is set from previous load
116
- race = Race.find_by_event_id_and_pos( @event.id, race_pos )
117
- load_records( name, race_id: race.id ) # e.g. 2013/04-gp-monaco.txt in formula1.db
118
- elsif name =~ /(?:^|\/)seasons/ # NB: ^seasons or also possible at-austria!/seasons
119
- load_seasons( name )
120
- elsif name =~ /^leagues/
121
- if name =~ /club/
122
- # e.g. leagues_club
123
- load_leagues( name, club: true )
124
- else
125
- # e.g. leagues
126
- load_leagues( name )
50
+ def load( name ) # convenience helper for all-in-one reader
51
+
52
+ logger.debug "enter load( name=>>#{name}<<, include_path=>>#{include_path}<<)"
53
+
54
+ if name =~ /^circuits/ # e.g. circuits.txt in formula1.db
55
+ load_tracks( name )
56
+ elsif name =~ /^drivers/ # e.g. drivers.txt in formula1.db
57
+ load_persons( name )
58
+ elsif name =~ /^teams/ # e.g. teams.txt in formula1.db
59
+ load_teams( name )
60
+ elsif name =~ /\/races/ # e.g. 2013/races.txt in formula1.db
61
+ load_races( name )
62
+ elsif name =~ /\/squads/ || name =~ /\/rosters/ # e.g. 2013/squads.txt in formula1.db
63
+ load_rosters( name )
64
+ elsif name =~ /\/([0-9]{2})-/
65
+ race_pos = $1.to_i
66
+ # NB: assume @event is set from previous load
67
+ race = Race.find_by_event_id_and_pos( @event.id, race_pos )
68
+ load_records( name, race_id: race.id ) # e.g. 2013/04-gp-monaco.txt in formula1.db
69
+ elsif name =~ /(?:^|\/)seasons/ # NB: ^seasons or also possible at-austria!/seasons
70
+ load_seasons( name )
71
+ elsif name =~ /^leagues/
72
+ if name =~ /club/
73
+ # e.g. leagues_club
74
+ load_leagues( name, club: true )
75
+ else
76
+ # e.g. leagues
77
+ load_leagues( name )
78
+ end
79
+ elsif match_leagues_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/leagues/
80
+ # auto-add country code (from folder structure) for country-specific leagues
81
+ # e.g. at/leagues
82
+ country = Country.find_by_key!( country_key )
83
+ load_leagues( name, club: true, country_id: country.id )
127
84
  end
128
- elsif match_leagues_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/leagues/
129
- # auto-add country code (from folder structure) for country-specific leagues
130
- # e.g. at/leagues
131
- country = Country.find_by_key!( country_key )
132
- load_leagues( name, club: true, country_id: country.id )
133
- end
134
- elsif match_teams_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/teams/
135
- # auto-add country code (from folder structure) for country-specific teams
136
- # e.g. at/teams at/teams.2 de/teams etc.
137
- country = Country.find_by_key!( country_key )
138
- load_teams( name, club: true, country_id: country.id )
139
- end
140
- elsif name =~ /\/teams/
141
- if name =~ /club/
142
- # club teams (many countries)
143
- # e.g. club/europe/teams
144
- load_teams( name, club: true )
145
- else
146
- # assume national teams
147
- # e.g. world/teams amercia/teams_n
148
- load_teams( name, national: true )
85
+ elsif match_teams_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/teams/
86
+ # auto-add country code (from folder structure) for country-specific teams
87
+ # e.g. at/teams at/teams.2 de/teams etc.
88
+ country = Country.find_by_key!( country_key )
89
+ load_teams( name, club: true, country_id: country.id )
149
90
  end
150
- else
151
- logger.error "unknown sportdb fixture type >#{name}<"
152
- # todo/fix: exit w/ error
153
- end
154
- else # more than one item in record? assume fixture starting w/ event key
155
-
156
- # assume first item is key
157
- # assume second item is event plus fixture
158
- # assume option third,etc are fixtures (e.g. bl2, etc.)
159
- event_key = rec[0] # e.g. at.2012/13
160
- event_name = rec[1] # e.g. at/2012_13/bl
161
- fixture_names = rec[1..-1] # e.g. at/2012_13/bl, at/2012_13/bl2
162
-
163
- load_event( event_name )
164
- fixture_names.each do |fixture_name|
165
- load_fixtures( event_key, fixture_name )
166
- end
91
+ elsif name =~ /\/teams/
92
+ if name =~ /club/
93
+ # club teams (many countries)
94
+ # e.g. club/europe/teams
95
+ load_teams( name, club: true )
96
+ else
97
+ # assume national teams
98
+ # e.g. world/teams amercia/teams_n
99
+ load_teams( name, national: true )
167
100
  end
168
-
169
- end # each ary
101
+ elsif name =~ /\/(\d{4}|\d{4}_\d{2})\// # e.g. must match /2012/ or /2012_13/
102
+ load_event( name )
103
+ event = fetch_event( name )
104
+ fixtures = fetch_event_fixtures( name )
105
+ fixtures.each do |fx|
106
+ load_fixtures( event.key, fx )
107
+ end
108
+ else
109
+ logger.error "unknown sportdb fixture type >#{name}<"
110
+ # todo/fix: exit w/ error
111
+ end
170
112
  end # method load
171
113
 
172
114
 
@@ -245,6 +187,44 @@ class Reader
245
187
  end # load_seasons
246
188
 
247
189
 
190
+ def fetch_event_fixtures( name )
191
+ # todo: merge with fetch_event to make it single read op - why? why not??
192
+ reader = HashReaderV2.new( name, include_path )
193
+
194
+ fixtures = []
195
+
196
+ reader.each_typed do |key, value|
197
+ if key == 'fixtures' && value.kind_of?( Array )
198
+ logger.debug "fixtures:"
199
+ logger.debug value.to_json
200
+ ## todo: make sure we get an array!!!!!
201
+ fixtures = value
202
+ else
203
+ # skip; do nothing
204
+ end
205
+ end # each key,value
206
+
207
+ if fixtures.empty?
208
+ logger.warn "no fixtures found for event - >#{name}<; assume fixture name is the same as event"
209
+ fixtures = [name]
210
+ else
211
+ ## add path to fixtures (use path from event e.g)
212
+ # - bl + at-austria!/2012_13/bl -> at-austria!/2012_13/bl
213
+ # - bl_ii + at-austria!/2012_13/bl -> at-austria!/2012_13/bl_ii
214
+
215
+ dir = File.dirname( name ) # use dir for fixtures
216
+
217
+ fixtures = fixtures.map do |fx|
218
+ fx_new = "#{dir}/#{fx}" # add path upfront
219
+ logger.debug "fx: #{fx_new} | >#{fx}< + >#{dir}<"
220
+ fx_new
221
+ end
222
+ end
223
+
224
+ fixtures
225
+ end
226
+
227
+
248
228
  def fetch_event( name )
249
229
  # get/fetch/find event from yml file
250
230
 
@@ -345,7 +325,7 @@ class Reader
345
325
  event_attribs['team3'] = false
346
326
  else
347
327
  ## todo: add a source location struct to_s or similar (file, line, col)
348
- logger.error "unknown event attrib; skipping attrib"
328
+ logger.error "unknown event attrib #{key}; skipping attrib"
349
329
  end
350
330
 
351
331
  end # each key,value
@@ -1,6 +1,6 @@
1
1
 
2
2
  module SportDb
3
- VERSION = '1.6.16'
3
+ VERSION = '1.6.17'
4
4
  end
5
5
 
6
6
  ###########################################
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.16
4
+ version: 1.6.17
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-06-25 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: worlddb
16
- requirement: &15927624 !ruby/object:Gem::Requirement
16
+ requirement: &16188720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.7'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *15927624
24
+ version_requirements: *16188720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: commander
27
- requirement: &15926976 !ruby/object:Gem::Requirement
27
+ requirement: &16188324 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 4.1.3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *15926976
35
+ version_requirements: *16188324
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdoc
38
- requirement: &15926508 !ruby/object:Gem::Requirement
38
+ requirement: &16187760 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '4.0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *15926508
46
+ version_requirements: *16187760
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: hoe
49
- requirement: &15926088 !ruby/object:Gem::Requirement
49
+ requirement: &16187424 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '3.6'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *15926088
57
+ version_requirements: *16187424
58
58
  description: sportdb - sport.db command line tool
59
59
  email: opensport@googlegroups.com
60
60
  executables: