Class: GamedayCliGem::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject

Main program loop



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

def call  #Main program loop
  GamedayCliGem::Scraper.new.make_games
  start
end

#goodbyeObject

exit program method



76
77
78
79
80
81
82
# File 'lib/gameday_cli_gem/cli.rb', line 76

def goodbye  #exit program method
  system "clear"
  puts ""
  puts "See you tomorrow for the next game!"
  puts ""
  sleep 0.5
end

#list_gamesObject



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/gameday_cli_gem/cli.rb', line 8

def list_games
    GamedayCliGem::Game.all.each_with_index do |game, index|
      if !game.news_url.nil?
        puts "#{index+1}. | #{game.league} | #{game.team1} vs. #{game.team2} - #{game.start_time} - News Available"
      elsif game.start_time.length < 1
        puts "#{index+1}. | #{game.league} | #{game.team1} vs. #{game.team2} - ONGOING "
      else
        puts "#{index+1}. | #{game.league} | #{game.team1} vs. #{game.team2} - #{game.start_time} "
      end
  end
end

#startObject

menu interface. navigates to individual games, or daily games listing



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
67
68
69
70
71
72
73
74
# File 'lib/gameday_cli_gem/cli.rb', line 20

def start  #menu interface. navigates to individual games, or daily games listing
   puts "-------------------"
   puts "Welcome to Gameday!"
   puts "-------------------"
   puts "Today is #{DateTime.now.strftime('%m/%d/%Y')} -"
   puts "Here are Today's Games:"
   puts
  list_games
  puts ""
  puts "Select any game with 'News Available' for more info. Or, type [Exit] to leave."
  input = gets.chomp.downcase
   if input == "exit"
     goodbye
   else
    system "clear"
      if GamedayCliGem::Game.find(input.to_i) && GamedayCliGem::Game.find(input.to_i).news_url.nil? #found game, but no news url to dig into
          puts "No news is currently available for that game. Please check back later tonight!"
          puts ""
          puts ""
          puts "------------------------------"
          puts "Press enter to return to main menu."
          input = gets.chomp
          start
      elsif !GamedayCliGem::Game.find(input.to_i) #did not find game by number
          puts "Invalid game selection! Please input a valid game number. [1 - #{GamedayCliGem::Game.all.length}]"
          puts ""
          puts ""
          puts "------------------------------"
          puts "Press enter to return to main menu."
          input = gets.chomp
          start
      elsif GamedayCliGem::Game.find(input.to_i) && !GamedayCliGem::Game.find(input.to_i).news_url.nil? #found game and it has a news_url to dig into
        game = GamedayCliGem::Game.find(input.to_i)
          puts "------------------------------"
          puts game.headline
          puts "------------------------------"
          game.final_score
          puts ""
          puts game.recap
          puts "------------------------------"
          puts "Enter [List] to return to today's games, or [Exit] to quit."
          input = gets.chomp.downcase
          case input
            when "list"
              system "clear"
              start
            when "exit"
              goodbye
            else
              system "clear"
              start
            end
          end
      end
end