Class: MLBScoreboard::CLI

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

Instance Method Summary collapse

Instance Method Details

#box_score(user_input) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/cli.rb', line 40

def box_score(user_input)
  user_input = user_input.to_i - 1
  
  teams = MLBScoreboard::Matchups.scrape_teams(user_input)
  runs = MLBScoreboard::Matchups.scrape_runs(user_input)
  hits = MLBScoreboard::Matchups.scrape_hits(user_input)
  errors = MLBScoreboard::Matchups.scrape_errors(user_input)
  home_line = [teams[0], runs[0], hits[0], errors[0]]
  away_line = [teams[1], runs[1], hits[1], errors[1]]
  
  rows = []
  rows << home_line
  rows << away_line
  
  table = Terminal::Table.new :headings => ['Team', 'R', 'H', 'E'], :rows => rows

  puts table
  
  puts "\nWould you like to see the list again or exit?"
  user_input = gets.strip
  if user_input == "exit"
    exit
  else
    menu
  end
  
end

#goodbyeObject



68
69
70
71
72
# File 'lib/cli.rb', line 68

def goodbye
  puts "*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*"
  puts "*~* Thanks for using Scoreboard *~*"
  puts "*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*"
end

#list_gamesObject



32
33
34
35
36
37
38
# File 'lib/cli.rb', line 32

def list_games
  puts "\nYesterday's Games Around the MLB"
  @matchups = MLBScoreboard::Matchups.today
  @matchups.each.with_index(1) do |matchup, index|
    puts "#{index}. #{matchup}"
  end
end


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cli.rb', line 15

def menu
  list_games
  puts "\n"
  puts "Please enter the number of the game to see the details or type exit: "
  user_input = gets.strip.to_i
  
  if user_input > 0 && user_input <= @matchups.length
    box_score(user_input)
  elsif user_input > @matchups.length
    menu
  elsif user_input == "exit"
    exit
  else
    list_games
  end
end

#startObject



3
4
5
6
7
# File 'lib/cli.rb', line 3

def start
  welcome
  menu
  goodbye
end

#welcomeObject



9
10
11
12
13
# File 'lib/cli.rb', line 9

def welcome
  puts "*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*"
  puts "*~* Welcome to MLB Scoreboard *~*"
  puts "*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*"
end