Class: FootballNow::CLI
- Inherits:
-
Object
- Object
- FootballNow::CLI
- Defined in:
- lib/cli.rb
Instance Method Summary collapse
- #call ⇒ Object
- #get_standings(league) ⇒ Object
- #get_user_input ⇒ Object
- #goodbye_message ⇒ Object
- #list_all_results(team) ⇒ Object
- #list_leagues ⇒ Object
- #list_recent_results(league) ⇒ Object
- #list_stats(team) ⇒ Object
- #list_teams(league) ⇒ Object
- #load_all_data ⇒ Object
- #print_table(table) ⇒ Object
- #welcome_screen ⇒ Object
Instance Method Details
#call ⇒ Object
3 4 5 6 7 |
# File 'lib/cli.rb', line 3 def call welcome_screen list_leagues end |
#get_standings(league) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/cli.rb', line 63 def get_standings(league) table = league.get_standings puts "" puts "#{league.name.upcase} : Up to Round #{league.current_round}" puts "==========================================" print_table(table) puts "" puts "Hit enter to return to league list or exit to quit." get_user_input.downcase == "exit" ? : list_leagues end |
#get_user_input ⇒ Object
167 168 169 |
# File 'lib/cli.rb', line 167 def get_user_input gets.strip end |
#goodbye_message ⇒ Object
162 163 164 165 |
# File 'lib/cli.rb', line 162 def puts "Until next time!" exit 0 end |
#list_all_results(team) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/cli.rb', line 117 def list_all_results(team) puts "" puts "#{team.name.upcase}: League Results" puts "" team.matches.each do |match| puts "Round #{match.round}:" puts " #{match.home_score} #{match.home_team.name}" puts " #{match.away_score} #{match.away_team.name}" puts "" end puts "Hit enter to go back or exit to quit." if get_user_input.downcase == "exit" end |
#list_leagues ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 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 |
# File 'lib/cli.rb', line 9 def list_leagues puts "\n\n" puts "Available Leagues:" puts "==================" FootballNow::League.print_leagues puts "" puts "You can:" puts " - type `<#> recent results` for scores" puts " - type `<#> get standings` for the league table" puts " - type `<#> list teams` to explore a team indepth" puts " - type `exit` to quit now." puts "" puts "Usage: typing `1 list teams` will list all teams in the first league listed." puts "" puts "What would you like to do?" input = get_user_input league = FootballNow::League.get_league_by_index(input.split("").first.to_i - 1) if input =~ /^\d/ case input when "exit" when /^\D/ puts "Sorry, I didn't understand..." list_leagues when /recent results/ list_recent_results(league) list_leagues when /get standings/ get_standings(league) when /list teams/ list_teams(league) else puts "Sorry, I didn't understand..." list_leagues end end |
#list_recent_results(league) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cli.rb', line 47 def list_recent_results(league) puts "" puts "#{league.name.upcase}" puts "Round #{league.current_round}:" puts "" FootballNow::Match.get_recent_results(league).each do |result| puts " #{result.home_score} #{result.home_team.name}" puts " #{result.away_score} #{result.away_team.name}" puts "" end puts "Hit enter to go back or exit to quit." if get_user_input.downcase == "exit" end |
#list_stats(team) ⇒ Object
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/cli.rb', line 132 def list_stats(team) puts "" puts "#{team.name.upcase}: League Stats" puts "" format = '%-5s %-5s %-8s %-10s %-10s %-13s %s' puts format % ['Wins', 'Draws', 'Losses', 'Points', 'Goals For', 'Goals Against', 'Matches Played'] puts format % [ team.wins, team.draws, team.losses, team.points, team.goals_for, team.goals_against, team.matches.size ] puts "Hit enter to go back or exit to quit." if get_user_input.downcase == "exit" end |
#list_teams(league) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/cli.rb', line 76 def list_teams(league) puts "" puts "#{league.name.upcase} : Up to Round #{league.current_round}" puts "" format = '%-4s %-20s' league.teams.sort_by{|team| team.name}.each_with_index do |team, index| puts format % [index + 1, team.name] end puts "" puts "You can:" puts " - type `<#> results` for all results" puts " - type `<#> stats` for all avaulable stats" puts " - type `back` to return to the first menu" puts " - type `exit` to quit now." puts "" puts "Usage: typing `1 results` will list all results for that team." puts "" puts "What would you like to do?" input = get_user_input team = league.teams.sort_by{|team| team.name}[input.to_i - 1] if input =~ /^\d/ case input when /results/ list_all_results(team) list_teams(league) when /stats/ list_stats(team) list_teams(league) when /back/ list_leagues when /exit/ else puts "Sorry, I didn't understand you." list_teams end end |
#load_all_data ⇒ Object
156 157 158 159 160 |
# File 'lib/cli.rb', line 156 def load_all_data puts "Loading data from www.soccer24.com..." puts "This may take a minute or two..." FootballNow::Importer.generate end |
#print_table(table) ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/cli.rb', line 143 def print_table(table) format = '%-4s %-20s %-3s %-3s %-3s %s' puts format % ['#', 'Team', 'W', 'D', 'L', 'Pts'] table.each do |team| puts format % [ team.standing, team.name, team.wins, team.draws, team.losses, team.points] end end |
#welcome_screen ⇒ Object
151 152 153 154 |
# File 'lib/cli.rb', line 151 def welcome_screen puts "Welcome to Football Now" load_all_data end |