Class: NbaStats::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



3
4
5
6
# 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) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# 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) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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_teamsObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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_teamsObject



37
38
39
40
# 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

#startObject



8
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
# 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