class AhlScraper::SeasonStartDateFetcher

Public Class Methods

new(season_id, season_type) click to toggle source
# File lib/ahl_scraper/fetchers/season_start_date_fetcher.rb, line 5
def initialize(season_id, season_type)
  @season_id = season_id
  @season_type = season_type
end

Public Instance Methods

call() click to toggle source
# File lib/ahl_scraper/fetchers/season_start_date_fetcher.rb, line 10
def call
  return if %i[all_star_game exhibition].include? @season_type

  return SeasonDatesHelper::DATE_EXCEPTIONS[@season_id][:start_date] if SeasonDatesHelper::DATE_EXCEPTIONS.keys.include? @season_id

  JSON.parse(Nokogiri::HTML(URI.parse(url).open).text[5..-2], symbolize_names: true)
    &.first
    &.dig(:sections)
    &.first
    &.dig(:data)
    &.first
    &.dig(:row, :date_with_day)
end

Private Instance Methods

url() click to toggle source
# File lib/ahl_scraper/fetchers/season_start_date_fetcher.rb, line 26
def url
  "https://lscluster.hockeytech.com/feed/index.php?feed=statviewfeed&view=schedule&team=-1&season=#{@season_id}&month=#{@start_month}&location=homeaway&key=50c2cd9b5e18e390&client_code=ahl&site_id=1&callback=json"
end