Module: Worldfootball
- Defined in:
- lib/webget-football/worldfootball/page.rb,
lib/webget-football/worldfootball/config.rb,
lib/webget-football/worldfootball/leagues.rb,
lib/webget-football/worldfootball/download.rb,
lib/webget-football/worldfootball/page_report.rb,
lib/webget-football/worldfootball/leagues/asia.rb,
lib/webget-football/worldfootball/page_schedule.rb,
lib/webget-football/worldfootball/leagues/europe.rb,
lib/webget-football/worldfootball/leagues/pacific.rb,
lib/webget-football/worldfootball/leagues/north_america.rb,
lib/webget-football/worldfootball/leagues/south_america.rb,
lib/webget-football/worldfootball/leagues/europe--central.rb,
lib/webget-football/worldfootball/leagues/europe--eastern.rb,
lib/webget-football/worldfootball/leagues/europe--western.rb,
lib/webget-football/worldfootball/leagues/europe--northern.rb,
lib/webget-football/worldfootball/leagues/europe--southern.rb,
lib/webget-football/worldfootball/leagues/europe--british_isles.rb
Defined Under Namespace
Classes: Configuration, League, Metal, Page
Constant Summary collapse
- LEAGUES =
[LEAGUES_EUROPE, LEAGUES_NORTH_AMERICA, LEAGUES_SOUTH_AMERICA, LEAGUES_PACIFIC, LEAGUES_ASIA].reduce({}) { |mem,h| mem.merge!( h ); mem }
- 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 {}
/{ [^}]+ }/x
- SEASON_RE =
e.g. 2000 or 2000-2001
/[0-9]{4} (?: -[0-9]{4} )? /x
- LEAGUES_ASIA =
{ # /chn-super-league-2020/ 'cn.1' => { pages: 'chn-super-league' }, # /jpn-j1-league-2020/ 'jp.1' => { pages: 'jpn-j1-league' }, =begin 2020 -- >/alle_spiele/kor-k-league-1-2020/< 2019 Meisterschaft -- >/alle_spiele/kor-k-league-1-2019-meisterschaft/< 2019 Abstieg -- >/alle_spiele/kor-k-league-1-2019-abstieg/< 2019 -- >/alle_spiele/kor-k-league-1-2019/< 2018 Meisterschaft -- >/alle_spiele/kor-k-league-1-2018-meisterschaft/< 2018 Abstieg -- >/alle_spiele/kor-k-league-1-2018-abstieg/< 2018 -- >/alle_spiele/kor-k-league-classic-2018/< 2017 Meisterschaft -- >/alle_spiele/kor-k-league-classic-2017-meisterschaft/< 2017 Abstieg -- >/alle_spiele/kor-k-league-classic-2017-abstieg/< 2017 -- >/alle_spiele/kor-k-league-classic-2017/< 2016 Meisterschaft -- >/alle_spiele/kor-k-league-classic-2016-meisterschaft/< 2016 Abstieg -- >/alle_spiele/kor-k-league-classic-2016-abstieg/< 2016 -- >/alle_spiele/kor-k-league-2016/< 2015 Meisterschaft -- >/alle_spiele/kor-k-league-2015-meisterschaft/< 2015 Abstieg -- >/alle_spiele/kor-k-league-2015-abstieg/< 2015 -- >/alle_spiele/kor-k-league-2015/< =end ### todo/fix: time-zone offset!!!!!!!! # /kor-k-league-1-2020/ # /kor-k-league-1-2019-meisterschaft/ # /kor-k-league-1-2019-abstieg/ 'kr.1' => { pages: { 'kor-k-league-1-{season}' => 'Regular Season', # 1 'kor-k-league-1-{season}-meisterschaft' => 'Playoffs - Championship', # 2 'kor-k-league-1-{season}-abstieg' => 'Playoffs - Relegation', # 3 }, season: ->( season ) { case season when Season('2020') then [1] # just getting started when Season('2019') then [1,2,3] end } }, }
- LEAGUES_EUROPE =
{}
- LEAGUES_PACIFIC =
{ # /nzl-nz-football-championship-2019-2020/ # /nzl-nz-football-championship-2018-2019-playoffs/ 'nz.1' => { pages: { 'nzl-nz-football-championship-{season}' => 'Regular Season', # 1 'nzl-nz-football-championship-{season}-playoffs' => 'Playoff Finals', # 2 }, season: ->( season ) { case season when Season('2019/20') then [1] ## covid-19 - no playoffs/finals when Season('2018/19') then [1,2] end } }, }
- LEAGUES_NORTH_AMERICA =
{ # todo/fix: adjust date/time by -6 or 7 hours!!! # /can-canadian-championship-2020/ # - Qual. 1. Runde # - Qual. 2. Runde # - Qual. 3. Runde # todo/fix: check for leagues - premier league? championship? soccer league? # 'ca.1' => { slug: 'can-canadian-championship' }, # todo/fix: adjust date/time by -7 hours!!! ## e.g. 25.07.2020 02:30 => 24.07.2020 19.30 # 11.01.2020 04:00 => 10.01.2020 21.00 # # e.g. /mex-primera-division-2020-2021-apertura/ # /mex-primera-division-2019-2020-clausura/ # /mex-primera-division-2019-2020-apertura-playoffs/ # - Viertelfinale # - Halbfinale # - Finale # /mex-primera-division-2018-2019-clausura-playoffs/ 'mx.1' => { pages: { 'mex-primera-division-{season}-apertura' => 'Apertura', # 1 'mex-primera-division-{season}-apertura-playoffs' => 'Apertura - Liguilla', # 2 'mex-primera-division-{season}-clausura' => 'Clausura', # 3 'mex-primera-division-{season}-clausura-playoffs' => 'Clausura - Liguilla', # 4 }, season: ->( season ) { case season when Season('2020/21') then [1] # just getting started when Season('2019/20') then [1,2,3] # covid-19 - no liguilla when Season('2010/11')..Season('2018/19') then [1,2,3,4] end } }, }
- LEAGUES_SOUTH_AMERICA =
{ # todo/fix: adjust date/time by -6 or 7 hours!!! # /bra-serie-a-2020/ 'br.1' => { pages: 'bra-serie-a' }, }
Class Method Summary collapse
- .config ⇒ Object
-
.configure {|config| ... } ⇒ Object
lets you use Worldfootball.configure do |config| config.convert.out_dir = ‘./o’ end.
-
.find_league(key) ⇒ Object
league info lookup.
- .find_page(slug) ⇒ Object
- .find_page!(slug) ⇒ Object
- .norm_slug(slug) ⇒ Object
-
.reports(league:, season:, cache: true) ⇒ Object
todo/check: rename to reports_for_schedule or such - why? why not?.
-
.schedule(league:, season:) ⇒ Object
porcelain “api”.
Class Method Details
.config ⇒ Object
15 |
# File 'lib/webget-football/worldfootball/config.rb', line 15 def self.config() @config ||= Configuration.new; end |
.configure {|config| ... } ⇒ Object
lets you use
Worldfootball.configure do |config|
config.convert.out_dir = './o'
end
14 |
# File 'lib/webget-football/worldfootball/config.rb', line 14 def self.configure() yield( config ); end |
.find_league(key) ⇒ Object
league info lookup
87 88 89 90 91 92 93 94 |
# 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) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# 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) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# 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) ⇒ Object
107 108 109 110 |
# 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) ⇒ Object
todo/check: rename to reports_for_schedule or such - why? why not?
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# 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 || Metal.download_reports_for_schedule( [:slug], cache: cache ) end # each page end |
.schedule(league:, season:) ⇒ Object
porcelain “api”
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# 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 || Metal.download_schedule( [:slug] ) end # each page end |