Class: NbaStats::CLI
- Inherits:
-
Object
- Object
- NbaStats::CLI
- Defined in:
- lib/nba_stats/cli.rb
Instance Method Summary collapse
Instance Method Details
#call ⇒ Object
3 4 5 |
# File 'lib/nba_stats/cli.rb', line 3 def call start end |
#choose_player ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/nba_stats/cli.rb', line 56 def choose_player puts "Enter a player name to see their individual stats: " requested_player = gets.strip while !NbaStats::Player.player_names.include? requested_player puts "That player isn't on this team. Try again." requested_player = gets.strip end player = NbaStats::Player.all.detect {|player| player.name == requested_player} stats_hash = NbaStats::Scraper.get_player_stats(player) player.add_player_stats(stats_hash) 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: " stats_table = Terminal::Table.new rows: rows puts stats_table end |
#choose_team ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/nba_stats/cli.rb', line 38 def choose_team puts "Enter a team name to see their roster: " requested_team = gets.strip while !NbaStats::Team.team_names.include? requested_team puts "That team doesn't exist. Try again." requested_team = gets.strip end team = NbaStats::Team.all.detect {|team| team.name == requested_team} team.add_players 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 roster_table = Terminal::Table.new rows: rows puts roster_table end |
#make_teams ⇒ Object
33 34 35 36 |
# File 'lib/nba_stats/cli.rb', line 33 def make_teams teams_array = NbaStats::Scraper.get_teams NbaStats::Team.create_from_collection(teams_array) end |
#start ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/nba_stats/cli.rb', line 7 def start puts "Welcome to the NBA Stats CLI Gem" puts "Here's the list of current teams" make_teams NbaStats::Team.all.each do |team| puts team.name end choose_team choose_player puts "Do you want to look up another player on this team? y/n" response = gets.strip while response == "y" choose_player puts "Do you want to look up another player on this team? y/n" response = gets.strip end puts "Do you want to look up another team? y/n" response = gets.strip if response == "y" start end end |