Class: YankeeScore::CLI
- Inherits:
-
Object
- Object
- YankeeScore::CLI
- Defined in:
- lib/yankee_score/cli.rb
Instance Method Summary collapse
- #bye_message ⇒ Object
- #call ⇒ Object
- #greet_user ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #list_games ⇒ Object
- #menu ⇒ Object
- #print_game(game) ⇒ Object
- #print_games ⇒ Object
- #search_team(team_abbrev) ⇒ Object
Constructor Details
#initialize ⇒ CLI
3 4 5 6 |
# File 'lib/yankee_score/cli.rb', line 3 def initialize @score_scraper = YankeeScore::ScoreScraper.new @score_scraper.load_games end |
Instance Method Details
#bye_message ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/yankee_score/cli.rb', line 86 def puts puts "Bye!" puts sleep 0.5 puts "+----------------------------------------------+" puts "| It ain't over till it's over. - Yogi Berra |" puts "+----------------------------------------------+" puts end |
#call ⇒ Object
11 12 13 14 15 |
# File 'lib/yankee_score/cli.rb', line 11 def call greet_user search_team("NYY") end |
#greet_user ⇒ Object
17 18 19 |
# File 'lib/yankee_score/cli.rb', line 17 def greet_user puts "Welcome to Yankee Score CLI" end |
#list_games ⇒ Object
97 98 99 100 101 |
# File 'lib/yankee_score/cli.rb', line 97 def list_games YankeeScore::Game.all.each do |game| puts " #{game.away_team.name} @ #{game.home_team.name} #{game.score || game.start_time}" end end |
#menu ⇒ Object
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 |
# File 'lib/yankee_score/cli.rb', line 21 def input = nil while input != "exit" puts puts "1. Search another team" puts "2. Show all teams" input = gets.strip case input when "1" list_games puts "Enter Team initials to select team." answer = gets.strip.upcase search_team(answer) when "2" print_games when "exit" exit else end end end |
#print_game(game) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/yankee_score/cli.rb', line 57 def print_game(game) puts puts " ============" puts " #{game.away_team.name} | #{game.away_team.runs || "-"}" puts " -----------" puts " #{game.home_team.name} | #{game.home_team.runs || "-"}" puts " ============" puts puts "Game Start: #{game.start_time}" unless game.is_over? puts "#{game.inning_state} #{game.inning.to_i.ordinalize}" if game.is_active? puts puts "Game Status: #{game.status}" end |
#print_games ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/yankee_score/cli.rb', line 78 def print_games YankeeScore::Game.all.each do |game| puts "===============================" print_game(game) puts "===============================" end end |
#search_team(team_abbrev) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/yankee_score/cli.rb', line 48 def search_team(team_abbrev) games = YankeeScore::Game.find_team_by_abbrev(team_abbrev) games.each do |game| print_game(game) end end |