Class: SportDb::LeagueConfig::LeagueItem

Inherits:
Object
  • Object
show all
Defined in:
lib/football-timezones/league_config.rb

Instance Method Summary collapse

Constructor Details

#initializeLeagueItem

Returns a new instance of LeagueItem.



17
18
19
# File 'lib/football-timezones/league_config.rb', line 17

def initialize
   @recs = []
end

Instance Method Details

#[](key) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/football-timezones/league_config.rb', line 45

def [](key)
    ## short cut - if only one or zero rec
    ##   return directly
    if @recs.empty?
        nil
    elsif @recs.size == 1 &&
          @recs[0]['start_season'].nil? &&
          @recs[0]['end_season'].nil?
        @recs[0][key.to_s]
    else   ### return proc that requires season arg
        case key.to_sym
        when :name      then  method(:name_by_season).to_proc
        when :basename  then  method(:basename_by_season).to_proc
        else
            nil  ## return nil - why? why not?
            ## raise ArgumentError, "invalid key #{key}; use :name or :basename"
        end
    end
end

#add(rec) ⇒ Object Also known as: <<



20
# File 'lib/football-timezones/league_config.rb', line 20

def add( rec ) @recs << rec; end

#basename_by_season(season) ⇒ Object



39
40
41
42
# File 'lib/football-timezones/league_config.rb', line 39

def basename_by_season( season )
    rec = find_by_season( season )
    rec ? rec['basename'] : nil
end

#find_by_season(season) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/football-timezones/league_config.rb', line 23

def find_by_season( season )
    @recs.each do |rec|
        start_season = rec['start_season']
        end_season   = rec['end_season']
        return rec  if (start_season.nil? || start_season <= season) &&
                       (end_season.nil? || end_season >= season)
    end
    nil
end

#name_by_season(season) ⇒ Object



34
35
36
37
# File 'lib/football-timezones/league_config.rb', line 34

def name_by_season( season )
    rec = find_by_season( season )
    rec ? rec['name'] : nil
end