class AhlScraper::Season

Attributes

id[R]
name[R]
season_type[R]

Public Class Methods

new(raw_data) click to toggle source
# File lib/ahl_scraper/resources/season.rb, line 7
def initialize(raw_data)
  @id = raw_data[:id].to_i
  @name = raw_data[:name]
  @season_type = set_season_type
  @division_data = %i[regular playoffs].include?(season_type) ? DivisionDataFetcher.new(@id).call : []
end

Public Instance Methods

abbreviation() click to toggle source
# File lib/ahl_scraper/resources/season.rb, line 14
def abbreviation
  @abbreviation ||=
    case season_type
    when :regular
      "#{start_year.to_s[-2..-1]}-#{end_year.to_s[-2..-1]}"
    when :playoffs
      "#{start_year.to_s[-2..-1]}PO"
    when :all_star_game
      "#{start_year.to_s[-2..-1]}ASG"
    when :exhibition
      "#{start_year.to_s[-2..-1]}-#{end_year.to_s[-2..-1]}EX"
    end
end
divisions() click to toggle source
# File lib/ahl_scraper/resources/season.rb, line 56
def divisions
  @divisions ||= @division_data.map { |d| d.dig(:headers, :name, :properties, :title) }
end
end_date() click to toggle source
# File lib/ahl_scraper/resources/season.rb, line 42
def end_date
  @end_date ||= set_end_date
end
end_year() click to toggle source
# File lib/ahl_scraper/resources/season.rb, line 46
def end_year
  @end_year ||=
    case season_type
    when :regular, :exhibition
      start_year + 1
    when :playoffs, :all_star_game
      start_year
    end
end
start_date() click to toggle source
# File lib/ahl_scraper/resources/season.rb, line 38
def start_date
  @start_date ||= set_start_date
end
start_year() click to toggle source
# File lib/ahl_scraper/resources/season.rb, line 28
def start_year
  @start_year ||=
    case season_type
    when :regular, :exhibition
      name[/(.*?)\-/].to_i
    when :playoffs, :all_star_game
      name[/(.*?) /].to_i
    end
end
teams() click to toggle source
# File lib/ahl_scraper/resources/season.rb, line 60
def teams
  @teams ||= %i[regular playoffs].include?(season_type) ? Seasons::TeamsService.new(@division_data).call : []
end

Private Instance Methods

set_end_date() click to toggle source
# File lib/ahl_scraper/resources/season.rb, line 86
def set_end_date
  return unless %i[playoffs regular].include? season_type

  day = SeasonEndDateFetcher.new(@id, season_type).call
  "#{day} #{end_year}"
end
set_season_type() click to toggle source
# File lib/ahl_scraper/resources/season.rb, line 66
def set_season_type
  case name
  when /Exhibition/
    :exhibition
  when /All-Star/
    :all_star_game
  when /Playoffs/
    :playoffs
  when /Regular/
    :regular
  end
end
set_start_date() click to toggle source
# File lib/ahl_scraper/resources/season.rb, line 79
def set_start_date
  return unless %i[playoffs regular].include? season_type

  day = SeasonStartDateFetcher.new(@id, season_type).call
  "#{day} #{start_year}"
end