133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
# File 'lib/leagues/timezones.rb', line 133
def find_zone( league:, season: )
raise ArgumentError, "league code as string|symbol expected" unless league.is_a?(String) || league.is_a?(Symbol)
@zones ||= begin
zones = {}
['timezones_africa',
'timezones_america',
'timezones_asia',
'timezones_europe',
'timezones_middle_east',
'timezones_pacific',
'timezones_world',].each do |name|
recs = read_csv( "#{SportDb::Module::Leagues.root}/config/#{name}.csv" )
recs.each do |rec|
zone = UTC.find_zone( rec['zone'] )
if zone.nil?
puts "!! ERROR - cannot find timezone in timezone db:"
pp rec
exit 1
end
zones[ rec['key']] = zone
end
end
zones
end
season = Season( season )
league_code = league.to_s.downcase
=begin
###
## map code here - why? why not?
## or (always) require canoncial code???
league_info = LeagueCodes.find_by( code: league, season: season )
league_code = if league_info
## lookup first try by league+season
league_info['code'] ## use canonical name
else
## fallback; no league found
## or report error in the future - why? why not?
league.to_s.downcase
end
=end
key = "#{league_code}+#{season}"
zone = @zones[key]
zone = @zones[league_code] if zone.nil?
if zone.nil?
code, _ = league_code.split( '.', 2 )
zone = @zones[code]
end
zone
end
|