Class: Worldfootball::LeagueConfig::LeagueItem

Inherits:
Object
  • Object
show all
Defined in:
lib/worldfootball/leagues.rb

Overview

nested inside LeagueConfig

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#keyObject (readonly)

Returns the value of attribute key.



10
11
12
# File 'lib/worldfootball/leagues.rb', line 10

def key
  @key
end

#slugObject (readonly)

Returns the value of attribute slug.



10
11
12
# File 'lib/worldfootball/leagues.rb', line 10

def slug
  @slug
end

Instance Method Details

#pages(season:) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/worldfootball/leagues.rb', line 90

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



79
80
81
82
83
84
85
86
87
88
# File 'lib/worldfootball/leagues.rb', line 79

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

#seasonsObject



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
# 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!!!!
      next if season == '2019-2021'
      next if season == '1958/1960'
      next if season == '1955/1958'

      season = Season.parse( season )

      seasons[ season.key ] ||= []
      seasons[ season.key] << [slug, stage]
   end
   seasons
  end
  @seasons
end