Class: SportSearch::EventSeasonSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/sportdb/search/sport.rb

Overview

virtual table for season lookup

note - use EventSeaon  to avoid name conflict with (global) Season class
   find a better name SeasonInfo or SeasonFinder or SeasonStore
                    or SeasonQ or ??

Instance Method Summary collapse

Constructor Details

#initialize(events:) ⇒ EventSeasonSearch

Returns a new instance of EventSeasonSearch.



260
261
262
# File 'lib/sportdb/search/sport.rb', line 260

def initialize( events: )
    @events = events
end

Instance Method Details

#find_by(date:, league:) ⇒ Object

todo/fix: find a better algo to guess season for date!!!



267
268
269
270
271
272
273
274
275
276
# File 'lib/sportdb/search/sport.rb', line 267

def find_by( date:, league: )
  date = Date.strptime( date, '%Y-%m-%d' )   if date.is_a?( String )

  infos = @events.seasons( league )

  infos.each do |info|
     return info.season   if info.include?( date )
  end
  nil
end