class BestNbaPlayersS18::CLI

Constants

COLORIER
URL

Public Class Methods

print_player(player) click to toggle source
print_players(from_number, order = "rank", stats = "") click to toggle source
print_players_group(by_input) click to toggle source
run() click to toggle source
# File lib/best_nba_players_18/cli.rb, line 11
def self.run
  collections = BestNbaPlayersS18::Scraper.scrape_page(URL)
  BestNbaPlayersS18::Players.create_players_from_collection collections
end
start() click to toggle source
# File lib/best_nba_players_18/cli.rb, line 16
def self.start
  run
  system "cls" or system "clear"
  puts "Welcome to best_nba_players_18 gem","--**player's trend ("+"upswing".colorize(:green)+", constant, "+"decline".colorize(:red)+ ") .**--\n"
  input = ""
  until input == "n" or input == "no"
    opt = -1
    until opt > 0 and opt <= 10
      puts "Invalid input!!! \n" if opt == 0 or opt >= 10
      rows = [
        ["1. List all players by ranking","2. List all players by Age"],
        ["3. List all players by points","4. List all players by rebounds"],
        ["5. List all players by assists","6. List all players by 3pt"],
        ["7. List all players by blocks","8. List all players by free throw"],
        ["9. Group by trend","10. Exit"],
      ]
      puts Terminal::Table.new :title => "Menu", :rows => rows, :style => {:all_separators => true}
      print "=> "
      opt = gets.strip.to_i

      system "cls" or system "clear"
    end
    
    break if opt == 10

    if opt != 9
      #sort the @@all by_input
      #return an array for stats
      order =  BestNbaPlayersS18::Players.sort opt

      until input == "n" or input == "no"
        puts "\n What number of players do you want to see? 1-20, 21-40, 41-60, 61-80 or 81-100?  "
        print "=> "
        n_palyer = gets.strip.to_i
        n_palyer = 1 if n_palyer == 0
        n_palyer = 80 if n_palyer > 100

        #print_players index
        print_players n_palyer, order  if order.class == String
        print_players n_palyer, order[0], order[1]  if order.class == Array

        puts "What player do you want to see more information on?"
        print "=> "
        input = gets.strip.to_i
        input = 100 if input > 100

        #print_player index
        player = BestNbaPlayersS18::Players.find input
        print_player player

        puts "Do you want to see information about another player? (y/n)"
        print "=> "
        input = gets.strip.downcase
      end
    else
      until input == "n" or input == "no"
        puts "\n What group of trends do you want to see?"," (1- constant, 2-"+" upswing".colorize(:green)+", 3-"+" decline".colorize(:red)+")"
        print "=> "
        n_trend = gets.strip.to_i
        n_trend = 1 if n_trend  == 0
        n_trend = 3 if n_trend > 3

        choices = ["neutral", "up", "down"]
        by_input = choices[n_trend-1]

        #print_players group by_input
        print_players_group by_input

        puts "What player do you want to see more information on?"
        print "=> "
        input = gets.strip.to_i
        sizeg = BestNbaPlayersS18::Players.group_size by_input
        input = sizeg if input > sizeg

        #print_player index
        player = BestNbaPlayersS18::Players.find_group input, by_input
        print_player player

        puts "Do you want to see information about another player? (y/n)"
        print "=> "
        input = gets.strip.downcase
      end
    end

    puts "Do you want to list all players? (y/n)"
    print "=> "
    input = gets.strip.downcase
    # system "cls" or system "clear"
  end

  puts "Goodbye !!"

end