class Worldfootball::League

Public Class Methods

new( key, data ) click to toggle source
# File lib/webget-football/worldfootball/leagues.rb, line 20
def initialize( key, data )
  @key  = key
  ## @data = data

  @pages       = data[:pages]
  @season_proc = data[:season] || ->(season) { nil }
end

Public Instance Methods

fill_slug( slug, season: ) click to toggle source

helper method

# File lib/webget-football/worldfootball/leagues.rb, line 68
def fill_slug( slug, season: )
  ## note: fill-in/check for place holders too
  slug = if slug.index( '{season}' )
           slug.sub( '{season}', season.to_path( :long ) )  ## e.g. 2010-2011
         elsif slug.index( '{end_year}' )
           slug.sub( '{end_year}', season.end_year.to_s )   ## e.g. 2011
         else
           ## assume convenience fallback - append regular season
           "#{slug}-#{season.to_path( :long )}"
        end

  puts "  slug=>#{slug}<"

  slug
end
key() click to toggle source
# File lib/webget-football/worldfootball/leagues.rb, line 28
def key()   @key; end
pages( season: ) click to toggle source
# File lib/webget-football/worldfootball/leagues.rb, line 30
def pages( season: )
  ## note: return for no stages / simple case - just a string
  ##   and for the stages case ALWAYS an array (even if it has only one page (with stage))

  if @pages.is_a?( String )
    # assume always "simple/regular" format w/o stages
    slug = @pages
    { slug: fill_slug( slug, season: season ) }
  else
     ## check for league format / stages
     ##   return array (of strings) or nil (for no stages - "simple" format)
     indices = @season_proc.call( season )
     if indices.nil?
       puts "!! ERROR - no configuration found for season >#{season}< for league >#{@key}< found; sorry"
       exit 1
     elsif indices.is_a?( Integer )  ## single number - single/regular format w/o stage
      # note: starting with 0 (always use idx-1) !!!
       slug = if @pages.is_a?( Array )
                @pages[indices-1]
              else ## assume hash (and key is page slug)
                @pages.keys[indices-1]
              end
       { slug: fill_slug( slug, season: season ) }
     else  ## assume regular case - array of integers
       recs = []
       indices.each do |idx|
          slug = key = @pages.keys[idx-1]
          recs << { slug:  fill_slug( slug, season: season ),
                    stage: @pages[key] }  ## note: include mapping for page to stage name!!
       end
       recs
    end
  end
end