Class: AtpRankings::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



2
3
4
5
6
7
8
9
# 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_athletesObject



38
39
40
41
42
43
44
# 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


46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/atp_rankings/cli.rb', line 46

def print_athlete(athlete)
  puts ""
  puts "--- #{athlete.name} ----------------------"
  puts ""
  puts "Current ATP Rank:             #{athlete.current_atp_rank}"
  puts "Turned Pro:                   #{athlete.turned_pro}"
  puts "Plays:                        #{athlete.orientation}"
  puts "Birthplace:                   #{athlete.birthplace}"
  puts "Coach(es):                    #{athlete.coach}"
  puts "Current ATP Record:           #{athlete.overall_record}"
  puts "Total # of Titles Won:        #{athlete.overall_titles}"
  puts "Total Prize Money Earned:     #{athlete.overall_prize_money_earned}"
  puts ""
end

#startObject



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