Class: NHLScores::Games

Inherits:
Object
  • Object
show all
Defined in:
lib/nhl_scores/games.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGames

Returns a new instance of Games.



7
8
9
10
# 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

Instance Attribute Details

#gamesObject (readonly)

Returns the value of attribute games.



3
4
5
# File 'lib/nhl_scores/games.rb', line 3

def games
  @games
end

Instance Method Details

#all(team_abbrev: nil) ⇒ Object



12
13
14
15
16
# 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) ⇒ Object



22
23
24
# 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) ⇒ Object



18
19
20
# 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) ⇒ Object



26
27
28
# 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