class AtpRankings::CLI

Public Instance Methods

call() click to toggle source
# File lib/atp_rankings/cli.rb, line 2
def call
  AtpRankings::Scraper.new.create_athletes
  puts "Welcome to Emirates ATP World Tour Race to London Rankings!"
  puts "Below are the current top 25 players in contention for a top 8 spot."
  puts ""
  list_athletes
  start
end
list_athletes() click to toggle source
# File lib/atp_rankings/cli.rb, line 38
def list_athletes
  format = '%-12s %-25s %-8s %-10s %-10s'
  puts format % ['RACE RANK', 'NAME', 'AGE', 'POINTS', 'TOURNAMENTS PLAYED']
  AtpRankings::Athlete.all.each_with_index do |athlete, i|
    puts format % [ athlete.rank, athlete.name, athlete.age, athlete.points, athlete.tourn_played ]
  end
end
print_athlete(athlete) click to toggle source
start() click to toggle source
# File lib/atp_rankings/cli.rb, line 11
def start
  puts ""
  puts "Please select a player based on ranking number:"
  input = gets.strip.to_i

  if input != 0 && input.between?(1, 25)
    athlete = AtpRankings::Athlete.find(input)
    print_athlete(athlete)
  else
    puts "Hey, something went wrong... Let's try again."
    start
  end

  puts ""
  puts "View another player? Enter Y/N:"
  input = gets.strip.downcase

  if input == "y"
    start
  else
    puts ""
    puts "Idemo!"
    puts ""
    exit
  end
end