Class: Worldfootball::LeagueConfig::LeagueItem
- Inherits:
-
Object
- Object
- Worldfootball::LeagueConfig::LeagueItem
- Defined in:
- lib/worldfootball/leagues.rb
Overview
nested inside LeagueConfig
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
Instance Method Summary collapse
-
#initialize(key:, slug:) ⇒ LeagueItem
constructor
A new instance of LeagueItem.
-
#log(msg) ⇒ Object
append to log.
- #pages(season:) ⇒ Object
- #pages!(season:) ⇒ Object
- #seasons ⇒ Object
Constructor Details
#initialize(key:, slug:) ⇒ LeagueItem
Returns a new instance of LeagueItem.
12 13 14 15 16 17 |
# File 'lib/worldfootball/leagues.rb', line 12 def initialize( key:, slug: ) @key = key @slug = slug @seasons = nil end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
10 11 12 |
# File 'lib/worldfootball/leagues.rb', line 10 def key @key end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
10 11 12 |
# File 'lib/worldfootball/leagues.rb', line 10 def slug @slug end |
Instance Method Details
#log(msg) ⇒ Object
append to log
113 114 115 116 117 118 |
# File 'lib/worldfootball/leagues.rb', line 113 def log( msg ) ### append to log File.open( './logs.txt', 'a:utf-8' ) do |f| f.write( msg ) f.write( "\n" ) end end |
#pages(season:) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/worldfootball/leagues.rb', line 93 def pages( season: ) ### lookup league pages/slugs by season season = Season( season ) ## note: assume reverse chronological order ## reverse here ## e.g. ## [["aut-bundesliga-2023-2024-qualifikationsgruppe", "Qualifikationsgruppe"], ## ["aut-bundesliga-2023-2024-playoff", "Playoff"], ## ["aut-bundesliga-2023-2024-meistergruppe", "Meistergruppe"], ## ["aut-bundesliga-2023-2024", nil]] ## => ## [["aut-bundesliga-2023-2024", nil], ## ["aut-bundesliga-2023-2024-meistergruppe", "Meistergruppe"], ## ["aut-bundesliga-2023-2024-playoff", "Playoff"], ## ["aut-bundesliga-2023-2024-qualifikationsgruppe", "Qualifikationsgruppe"]] recs = seasons[season.key] recs ? recs.reverse : nil end |
#pages!(season:) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/worldfootball/leagues.rb', line 82 def pages!( season: ) pages = pages( season: season ) if pages.nil? puts "!! ERROR - no season #{season} found for #{key}; seasons incl:" puts seasons.keys.join( ', ' ) puts " #{seasons.keys.size} season(s)" exit 1 end pages end |
#seasons ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/worldfootball/leagues.rb', line 20 def seasons ## auto-(down)load on first request @seasons ||= begin ### todo/fix: ## use from cache if not older than 1 (or 5/10?) hour(s) or such ## why? why not? schedule_url = Worldfootball::Metal.schedule_url( @slug ) if Webcache.expired_in_1d?( schedule_url ) Worldfootball::Metal.download_schedule( @slug ) end page = Worldfootball::Page::Schedule.from_cache( @slug ) ## pp page.seasons =begin [{:text=>"2024/2025", :ref=>"aut-oefb-cup-2024-2025"}, {:text=>"2023/2024", :ref=>"aut-oefb-cup-2023-2024"}, {:text=>"2022/2023", :ref=>"aut-oefb-cup-2022-2023"}, {:text=>"2021/2022", :ref=>"aut-oefb-cup-2021-2022"}, =end recs = page.seasons.map { |rec| [rec[:text], rec[:ref]] } pp recs puts " #{recs.size} record(s)" recs seasons = {} ## generate lookup table by season recs.each do |text,slug| ## ## fix upstream?? - allow multi-year seasons? why? why not? ## for now ignore special case and collect more real-world cases/samples ## if possible ## ["2019-2021 Playoffs", "regionalliga-bayern-2019-2021-playoffs"], ## ["2019-2021", "regionalliga-bayern-2019-2021"], ## ## ## ["1955/1958", "europa-league-1955-1958"]] ## ["1958/1960", "uefa-cup-1958-1960"], season, stage = text.split( ' ', 2 ) ## todo/fix: add a waring here and auto log to logs.txt!!!! if ['2019-2021', '1958/1960', '1955/1958' ].include?( season ) log( "!! WARN - seasons for league #{@key} incl. invalid season #{season} - slug #{slug}; skipping season" ) next ## note - skip invalid season entry end season = Season.parse( season ) seasons[ season.key ] ||= [] seasons[ season.key] << [slug, stage] end seasons end @seasons end |