class NbaStats::CLI
Public Instance Methods
call()
click to toggle source
# File lib/nba_stats/cli.rb, line 3 def call puts "Welcome to the NBA Stats CLI Gem" start end
display_player_stats(requested_player)
click to toggle source
# File lib/nba_stats/cli.rb, line 73 def display_player_stats(requested_player) player = NbaStats::Player.all.detect {|player| player.name == requested_player} player.add_player_stats rows = [["Points/Game", "Assists/Game", "Rebounds/Game", "Blocks/Game", "Steals/Game", "FG%", "3P%", "FT%", "Minutes/Game",]] rows << [player.points_pg, player.assists_pg, player.rebounds_pg, player.blocks_pg, player.steals_pg, player.fg_percentage, player.three_percentage, player.ft_percentage, player.minutes_pg] puts "Here are #{player.name}'s 2015-16 stats: " puts Terminal::Table.new rows: rows end
display_roster(requested_team)
click to toggle source
# File lib/nba_stats/cli.rb, line 58 def display_roster(requested_team) team = NbaStats::Team.all.detect {|team| team.name == requested_team} team.add_players if team.players.empty? puts team.name + " roster:" rows = [["Number", "Name", "Position", "Height", "Experience"]] team.players.each do |player| rows << [player.number, player.name, player.position, player.height, player.experience] end puts Terminal::Table.new rows: rows end
display_teams()
click to toggle source
# File lib/nba_stats/cli.rb, line 42 def display_teams make_teams if NbaStats::Team.all.empty? rows = [["Eastern Conference", "Western Conference"]] west_teams = NbaStats::Team.western_names east_teams = NbaStats::Team.eastern_names i = 0 while i < 15 rows << [east_teams[i], west_teams[i]] i += 1 end puts Terminal::Table.new rows: rows end
make_teams()
click to toggle source
# File lib/nba_stats/cli.rb, line 37 def make_teams teams_array = NbaStats::Scraper.get_teams NbaStats::Team.create_from_collection(teams_array) end
start()
click to toggle source
# File lib/nba_stats/cli.rb, line 8 def start puts "Input one of the team names below to load their roster." puts "Input exit to leave this program." puts "Here's the list of current teams" display_teams input = "" while input != "exit" puts "Input a team name to see their roster: " input = gets.strip if (NbaStats::Team.team_names.include? input) display_roster(input) puts "Input a player name to see their individual stats: " input = gets.strip while (NbaStats::Player.player_names.include? input) display_player_stats(input) puts "Input another player name from this team to see their stats." puts "Or input change teams to see another team's roster." input = gets.strip if input == "change teams" || input == "change team" start end end break end end end