class NHLScores::Games

Attributes

games[R]

Public Class Methods

new() click to toggle source
# File lib/nhl_scores/games.rb, line 7
def initialize
  response = HTTParty.get(ENDPOINT).sub("loadScoreboard(", "").sub(")", "")
  @games   = JSON.parse(response)["games"].map { |game_attributes| Game.new(game_attributes) }
end

Public Instance Methods

all(team_abbrev: nil) click to toggle source
# File lib/nhl_scores/games.rb, line 12
def all(team_abbrev: nil)
  return @games if team_abbrev.nil?
  team_name = team_name(team_abbrev)
  return @games.select { |game| game if game.includes_team?(team_name) }
end
in_progress(team_abbrev: nil) click to toggle source
# File lib/nhl_scores/games.rb, line 22
def in_progress(team_abbrev: nil)
  all(team_abbrev: team_abbrev).select { |game| game if game.status == "progress" }
end
recent(team_abbrev: nil) click to toggle source
# File lib/nhl_scores/games.rb, line 18
def recent(team_abbrev: nil)
  all(team_abbrev: team_abbrev).select { |game| game if game.status == "final" }
end
upcoming(team_abbrev: nil) click to toggle source
# File lib/nhl_scores/games.rb, line 26
def upcoming(team_abbrev: nil)
  all(team_abbrev: team_abbrev).select { |game| game if game.status == "" }
end

Private Instance Methods

team_name(team_abbrev) click to toggle source
# File lib/nhl_scores/games.rb, line 32
def team_name(team_abbrev)
  return TEAM_ABBREVIATIONS.fetch(team_abbrev.to_sym)
end