Class: SportDb::Import::EventIndex
- Inherits:
-
Object
- Object
- SportDb::Import::EventIndex
- Defined in:
- lib/sportdb/formats/event/event_index.rb
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
Class Method Summary collapse
Instance Method Summary collapse
- #add(recs) ⇒ Object
- #find_by(league:, season:) ⇒ Object
-
#initialize ⇒ EventIndex
constructor
A new instance of EventIndex.
Constructor Details
#initialize ⇒ EventIndex
Returns a new instance of EventIndex.
25 26 27 28 |
# File 'lib/sportdb/formats/event/event_index.rb', line 25 def initialize @events = [] @leagues = {} end |
Instance Attribute Details
#events ⇒ Object (readonly)
Returns the value of attribute events.
24 25 26 |
# File 'lib/sportdb/formats/event/event_index.rb', line 24 def events @events end |
Class Method Details
.build(path) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/sportdb/formats/event/event_index.rb', line 8 def self.build( path ) pack = Package.new( path ) ## lets us use direcotry or zip archive recs = [] pack.each_seasons do |entry| recs += EventInfoReader.parse( entry.read ) end recs index = new index.add( recs ) index end |
Instance Method Details
#add(recs) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sportdb/formats/event/event_index.rb', line 30 def add( recs ) @events += recs ## add to "linear" records recs.each do |rec| league = rec.league season = rec.season seasons = @leagues[ league.key ] ||= {} seasons[season.key] = rec end ## build search index by leagues (and season) end |
#find_by(league:, season:) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sportdb/formats/event/event_index.rb', line 43 def find_by( league:, season: ) league_key = league.is_a?( String ) ? league : league.key season_key = season.is_a?( String ) ? season : season.key seasons = @leagues[ league_key ] if seasons seasons[ season_key ] else nil end end |