module Worldfootball
Constants
- LEAGUES
- LEAGUES_ASIA
- LEAGUES_EUROPE
- LEAGUES_NORTH_AMERICA
- LEAGUES_PACIFIC
- LEAGUES_SOUTH_AMERICA
- PAGE_VAR_RE
“reverse” lookup by page - returns league AND season note: “blind” season template para - might be season or start_year etc.
e.g. {season} or {start_year} becomes {}
- SEASON_RE
e.g. 2000 or 2000-2001
Public Class Methods
config()
click to toggle source
# File lib/webget-football/worldfootball/config.rb, line 15 def self.config() @config ||= Configuration.new; end
configure() { |config| ... }
click to toggle source
lets you use
Worldfootball.configure do |config| config.convert.out_dir = './o' end
# File lib/webget-football/worldfootball/config.rb, line 14 def self.configure() yield( config ); end
find_league( key )
click to toggle source
# File lib/webget-football/worldfootball/leagues.rb, line 87 def self.find_league( key ) ## league info lookup data = LEAGUES[ key ] if data.nil? puts "!! ERROR - no league found for >#{key}<; add to leagues tables" exit 1 end League.new( key, data ) ## use a convenience wrapper for now end
find_page( slug )
click to toggle source
# File lib/webget-football/worldfootball/leagues.rb, line 165 def self.find_page( slug ) ## return league key and season season_str = nil norm = slug.sub( SEASON_RE ) do |match| ## replace season with var placeholder {} season_str = match ## keep reference to season str '{}' ## replace with {} end if season_str.nil? puts "!! ERROR: no season found in page slug >#{slug}<; sorry" exit 1 end rec = PAGES[ norm ] return nil if rec.nil? league_key = rec[:league] slug_tmpl = rec[:slug] season = if slug_tmpl.index( '{start_year}' ) ## todo/check - season_str must be year (e.g. 2020 or such and NOT 2020-2021) Season( "#{season_str.to_i}-#{season_str.to_i+1}" ) elsif slug_tmpl.index( '{end_year}' ) ## todo/check - season_str must be year (e.g. 2020 or such and NOT 2020-2021) Season( "#{season_str.to_i-1}-#{season_str.to_i}" ) else ## assume "regular" seasson - pass through as is Season( season_str ) end ## return hash table / record { league: league_key, season: season.key } end
find_page!( slug )
click to toggle source
# File lib/webget-football/worldfootball/leagues.rb, line 143 def self.find_page!( slug ) page = find_page( slug ) if page.nil? puts "!! ERROR: no mapping for page >#{slug}< found; sorry" season_str = nil norm = slug.sub( SEASON_RE ) do |match| ## replace season with var placeholder {} season_str = match ## keep reference to season str '{}' ## replace with {} end puts " season: >#{season_str}<" puts " slug (norm): >#{norm}<" puts ## pp PAGES exit 1 end page end
norm_slug( slug )
click to toggle source
# File lib/webget-football/worldfootball/leagues.rb, line 107 def self.norm_slug( slug ) ## assume convenience fallback - append regular season slug.index( '{' ) ? slug : "#{slug}-{season}" end
reports( league:, season:, cache: true )
click to toggle source
# File lib/webget-football/worldfootball/download.rb, line 22 def self.reports( league:, season:, cache: true ) ## todo/check: rename to reports_for_schedule or such - why? why not? season = Season( season ) ## cast (ensure) season class (NOT string, integer, etc.) league = find_league( league ) pages = league.pages( season: season ) ## if single (simple) page setup - wrap in array pages = pages.is_a?(Array) ? pages : [pages] pages.each do |page_meta| Metal.download_reports_for_schedule( page_meta[:slug], cache: cache ) end # each page end
schedule( league:, season: )
click to toggle source
porcelain “api”
# File lib/webget-football/worldfootball/download.rb, line 7 def self.schedule( league:, season: ) season = Season( season ) ## cast (ensure) season class (NOT string, integer, etc.) league = find_league( league ) pages = league.pages( season: season ) ## if single (simple) page setup - wrap in array pages = pages.is_a?(Array) ? pages : [pages] pages.each do |page_meta| Metal.download_schedule( page_meta[:slug] ) end # each page end