Class: SportDb::Import::EventIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/sportdb/formats/event/event_index.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEventIndex

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

#eventsObject (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