Sha256: 9400e2e6cf1b5a7e70c4d090cb43fb52534dcf6117d149016b00634f6a8a64ef

Contents?: true

Size: 1.01 KB

Versions: 12

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module AhlScraper
  class SeasonEndDateFetcher
    def initialize(season_id, season_type)
      @season_id = season_id
      @season_type = season_type
    end

    def call
      return if %i[all_star_game exhibition].include? @season_type

      return SeasonDatesHelper::DATE_EXCEPTIONS[@season_id][:end_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)
        &.last
        &.dig(:row, :date_with_day)
    end

    private

    def end_month
      SeasonDatesHelper::SEASON_MONTH_KEY[@season_type.to_sym][:end_month]
    end

    def url
      "https://lscluster.hockeytech.com/feed/index.php?feed=statviewfeed&view=schedule&team=-1&season=#{@season_id}&month=#{@end_month}&location=homeaway&key=50c2cd9b5e18e390&client_code=ahl&site_id=1&league_id=4&division_id=-1&lang=en&callback=json"
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ahl_scraper-0.4.0 lib/ahl_scraper/fetchers/season_end_date_fetcher.rb
ahl_scraper-0.3.8 lib/ahl_scraper/fetchers/season_end_date_fetcher.rb
ahl_scraper-0.3.7 lib/ahl_scraper/fetchers/season_end_date_fetcher.rb
ahl_scraper-0.3.6 lib/ahl_scraper/fetchers/season_end_date_fetcher.rb
ahl_scraper-0.3.5 lib/ahl_scraper/fetchers/season_end_date_fetcher.rb
ahl_scraper-0.3.4 lib/ahl_scraper/fetchers/season_end_date_fetcher.rb
ahl_scraper-0.3.3 lib/ahl_scraper/fetchers/season_end_date_fetcher.rb
ahl_scraper-0.3.2 lib/ahl_scraper/fetchers/season_end_date_fetcher.rb
ahl_scraper-0.3.1 lib/ahl_scraper/fetchers/season_end_date_fetcher.rb
ahl_scraper-0.3.0 lib/ahl_scraper/fetchers/season_end_date_fetcher.rb
ahl_scraper-0.2.0 lib/ahl_scraper/fetchers/season_end_date_fetcher.rb
ahl_scraper-0.1.1 lib/ahl_scraper/fetchers/season_end_date_fetcher.rb