class Scoreboard::Cli

Attributes

football_scoreboard[R]

Public Class Methods

new() click to toggle source
# File lib/scoreboard/cli.rb, line 10
def initialize
  @football_scoreboard = Scoreboard::FootballScoreboard.new
end

Public Instance Methods

adjust_team_score(team, score_type) click to toggle source
# File lib/scoreboard/cli.rb, line 68
def adjust_team_score(team, score_type)
  case score_type
  when "fg"
    puts "Field Goal, #{team.name}!"
    team.field_goal
  when "td"
    puts "Touch down, #{team.name}!"
    team.touchdown
  end
end
begin_reading_scores() click to toggle source
# File lib/scoreboard/cli.rb, line 37
def begin_reading_scores
  begin
    STDIN.each_line do |str|
      input = str.sub("\n", "").split(":")
      team = input[0] == "h" ? football_scoreboard.home_team : football_scoreboard.visitor_team
      adjust_team_score(team, input[1])

      puts "Scoreboard: #{football_scoreboard.score}"
    end
  # rubocop:disable UselessAssignment
  rescue Exception => ex
    # Only way to continue from here is just catch an Exception.
    # Ignore Rubocop warning, unfortunately catching only StandardError
    # doesnt rescue from the error.
    puts "You've ended the game!"
  end

  end_game
end
collect_team_input() click to toggle source
# File lib/scoreboard/cli.rb, line 29
def collect_team_input
  puts "Enter Home Team"
  football_scoreboard.home_team.name = $stdin.readline.sub("\n", "")

  puts "Enter Team 2 Name"
  football_scoreboard.visitor_team.name = $stdin.readline.sub("\n", "")
end
end_game() click to toggle source
# File lib/scoreboard/cli.rb, line 57
def end_game
  puts "Thanks for playing! Were sending the game data."
  Api.send_data(football_scoreboard)
  show_dashboard_url
end
print_initial_output() click to toggle source
show_dashboard_url() click to toggle source
# File lib/scoreboard/cli.rb, line 63
def show_dashboard_url
  puts "View the scoreboard dashboard: #{Api.dashboard_url}"
  puts "Weve sent your scoreboard data to our servers! Thanks for submitting!"
end
start(_args) click to toggle source
# File lib/scoreboard/cli.rb, line 81
def start(_args)
  collect_team_input
  print_initial_output

  begin
    begin_reading_scores
  rescue StandardError => ex
    puts "The game has ended. Final scores: #{football_scoreboard.score} - #{ex}"
  end
end