class NHLScores::CLI

Attributes

games[R]

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/nhl_scores/cli.rb, line 7
def initialize(*args)
  super
  @games = NHLScores::Games.new
end

Public Instance Methods

current() click to toggle source
# File lib/nhl_scores/cli.rb, line 21
def current
  games = @games.in_progress(team_abbrev: options['team'])
  output_games(games, 'current')
end
recent() click to toggle source
# File lib/nhl_scores/cli.rb, line 14
def recent
  games = @games.recent(team_abbrev: options['team'])
  output_games(games, 'recent')
end
upcoming() click to toggle source
# File lib/nhl_scores/cli.rb, line 28
def upcoming
  games = @games.upcoming(team_abbrev: options['team'])
  output_games(games, 'upcoming')
end

Private Instance Methods

output_current_game(game) click to toggle source
# File lib/nhl_scores/cli.rb, line 54
def output_current_game(game)
  if game.started?
    score_descriptor = score_descriptor_string(game)
    output = "IN PROGRESS: #{game.leader} #{score_descriptor} #{game.trailer} (#{game.leader_score}-#{game.trailer_score})"
  else
    output = "PRE GAME: #{game.home_team} vs. #{game.away_team}"
  end
  output += tv_string(game)
  puts output
end
output_games(games, type) click to toggle source
# File lib/nhl_scores/cli.rb, line 35
def output_games(games, type)
  puts
  title = "#{type.upcase} NHL GAMES"
  puts TextHelpers.yellow(title)
  puts TextHelpers.yellow("-" * title.length)
  if games.any?
    games.each do |game|
      send("output_#{type}_game", game)
    end
  else
    puts "There are no #{type} games."
  end
  puts
end
output_recent_game(game) click to toggle source
# File lib/nhl_scores/cli.rb, line 50
def output_recent_game(game)
  puts "#{game.date}: #{game.winner} defeat #{game.loser} (#{game.winner_score}-#{game.loser_score})"
end
output_upcoming_game(game) click to toggle source
# File lib/nhl_scores/cli.rb, line 65
def output_upcoming_game(game)
  output = "#{game.date} @ #{game.start_time} (PST):" + " #{game.home_team} vs. #{game.away_team}"
  output += tv_string(game)
  puts output
end
score_descriptor_string(game) click to toggle source
# File lib/nhl_scores/cli.rb, line 78
def score_descriptor_string(game)
  return "tied with" if game.home_team_score == game.away_team_score
  return "lead"
end
tv_string(game) click to toggle source
# File lib/nhl_scores/cli.rb, line 71
def tv_string(game)
  return " on #{game.ustv} (US)" if !game.ustv.empty? && game.catv.empty?
  return " on #{game.catv} (CA)" if !game.catv.empty? && game.ustv.empty?
  return " on #{game.ustv} (US) & #{game.catv} (CA)" if !game.ustv.empty? && !game.catv.empty?
  return ""
end