Class: AhlScraper::SeasonTypeFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/ahl_scraper/fetchers/season_type_fetcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(season_id) ⇒ SeasonTypeFetcher

Returns a new instance of SeasonTypeFetcher.



5
6
7
# File 'lib/ahl_scraper/fetchers/season_type_fetcher.rb', line 5

def initialize(season_id)
  @season_id = season_id
end

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ahl_scraper/fetchers/season_type_fetcher.rb', line 9

def call
  season = JSON.parse(Nokogiri::HTML(URI.parse(url).open).text[5..-2], symbolize_names: true)[:seasons]
    &.find { |s| s[:id].to_i == @season_id.to_i }
  return nil unless season

  case season[:name]
  when /Regular/
    :regular
  when /All-Star/
    :all_star
  when /Playoffs/
    :playoffs
  when /Exhibition/
    :exhibition
  end
end