Class: AhlScraper::PlayoffBrackets::Series

Inherits:
Resource
  • Object
show all
Defined in:
lib/ahl_scraper/resources/playoff_brackets/series.rb

Constant Summary collapse

OVERRIDE_WINS_NEEDED =
{
  "36" => { "1" => 4 },
  "39" => { "1" => 4 },
  "33" => { "1" => 4 },
  "29" => { "1" => 4 },
  "15" => { "1" => 4 },
  "10" => { "1" => 4 },
  "7" => { "1" => 4 },
  "69" => { "1" => 4 },
  "72" => { "1" => 1, "2" => 1, "3" => 2, "4" => 2 },
  "76" => { "1" => 2, "2" => 3, "3" => 4, "4" => 4, "5" => 4 },
  "80" => { "1" => 2, "2" => 3, "3" => 3, "4" => 4, "5" => 4 },
  "default" => { "1" => 2, "2" => 3, "3" => 3, "4" => 4, "5" => 4 },
}.freeze

Instance Method Summary collapse

Methods inherited from Resource

#[], #each, #initialize, #inspect, #keys, #to_json, #values

Constructor Details

This class inherits a constructor from AhlScraper::Resource

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


46
47
48
49
# File 'lib/ahl_scraper/resources/playoff_brackets/series.rb', line 46

def active?
  @active ||= team_ids_present? && team1_wins < wins_needed && team2_wins < wins_needed if @active.nil?
  @active
end

#away_feeder_seriesObject



55
56
57
# File 'lib/ahl_scraper/resources/playoff_brackets/series.rb', line 55

def away_feeder_series
  @away_feeder_series ||= home_team_id == team1 ? @raw_data[:feeder_series2] : @raw_data[:feeder_series1]
end

#away_team_idObject



68
69
70
71
# File 'lib/ahl_scraper/resources/playoff_brackets/series.rb', line 68

def away_team_id
  @away_team_id = first_game&.dig(:visiting_team)&.to_i if @away_team_id.nil?
  @away_team_id
end

#away_team_winsObject



77
78
79
# File 'lib/ahl_scraper/resources/playoff_brackets/series.rb', line 77

def away_team_wins
  @away_team_wins ||= home_team_id == team1 ? team2_wins : team1_wins
end

#finished?Boolean

Returns:

  • (Boolean)


93
94
95
96
# File 'lib/ahl_scraper/resources/playoff_brackets/series.rb', line 93

def finished?
  @finished = winning_team_id.present? if @finished.nil?
  @finished
end

#gamesObject



85
86
87
# File 'lib/ahl_scraper/resources/playoff_brackets/series.rb', line 85

def games
  @games ||= @raw_data[:games].map { |game| Game.new(game) }
end

#home_feeder_seriesObject



51
52
53
# File 'lib/ahl_scraper/resources/playoff_brackets/series.rb', line 51

def home_feeder_series
  @home_feeder_series ||= home_team_id == team1 ? @raw_data[:feeder_series1] : @raw_data[:feeder_series2]
end

#home_team_idObject



63
64
65
66
# File 'lib/ahl_scraper/resources/playoff_brackets/series.rb', line 63

def home_team_id
  @home_team_id = first_game&.dig(:home_team)&.to_i if @home_team_id.nil?
  @home_team_id
end

#home_team_winsObject



73
74
75
# File 'lib/ahl_scraper/resources/playoff_brackets/series.rb', line 73

def home_team_wins
  @home_team_wins ||= home_team_id == team1 ? team1_wins : team2_wins
end

#idObject



21
22
23
# File 'lib/ahl_scraper/resources/playoff_brackets/series.rb', line 21

def id
  @id ||= @raw_data[:series_letter]
end

#logo_urlObject



33
34
35
# File 'lib/ahl_scraper/resources/playoff_brackets/series.rb', line 33

def logo_url
  @logo_url ||= @raw_data[:series_logo]
end

#nameObject



25
26
27
# File 'lib/ahl_scraper/resources/playoff_brackets/series.rb', line 25

def name
  @name ||= @raw_data[:series_name]
end

#roundObject



37
38
39
# File 'lib/ahl_scraper/resources/playoff_brackets/series.rb', line 37

def round
  @round ||= @raw_data[:round].to_i
end

#season_idObject



29
30
31
# File 'lib/ahl_scraper/resources/playoff_brackets/series.rb', line 29

def season_id
  @season_id ||= find_season_id
end

#started?Boolean

Returns:

  • (Boolean)


41
42
43
44
# File 'lib/ahl_scraper/resources/playoff_brackets/series.rb', line 41

def started?
  @started = @raw_data[:active] == "1" if @started.nil?
  @started
end

#tiesObject



81
82
83
# File 'lib/ahl_scraper/resources/playoff_brackets/series.rb', line 81

def ties
  @ties ||= @raw_data[:ties].to_i
end

#winning_team_idObject



59
60
61
# File 'lib/ahl_scraper/resources/playoff_brackets/series.rb', line 59

def winning_team_id
  @winning_team_id ||= @raw_data[:winner].empty? ? find_winner : @raw_data[:winner].to_i
end

#wins_neededObject



89
90
91
# File 'lib/ahl_scraper/resources/playoff_brackets/series.rb', line 89

def wins_needed
  @wins_needed ||= find_wins_needed
end