Class: University_cli

Inherits:
Object
  • Object
show all
Defined in:
lib/university_cli_app/university_cli.rb

Instance Method Summary collapse

Instance Method Details

#callObject



3
4
5
# File 'lib/university_cli_app/university_cli.rb', line 3

def call
  menu
end

#close_appObject



77
78
79
80
# File 'lib/university_cli_app/university_cli.rb', line 77

def close_app
  puts "Thank you for checking out the rankings. Good luck with your selection!"
  exit
end

#list_by_rankObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/university_cli_app/university_cli.rb', line 55

def list_by_rank
  puts "Please enter a number from 1-50 and press enter:"
  answer = gets.strip
  num = answer.to_i

  unless num >= 1 && num <= 50
    puts "Invalid. Please try again."
    answer = gets.strip
  end

  list = University_scraper.school_list
  list.each do |school|
    if answer == school[:rank]
      puts "#{school[:rank]}. #{school[:name]}"
      puts "#{school[:location].capitalize}"
      puts "#{school[:description]}"
      puts "Learn more at: #{school[:url]}."
      puts ""
    end
  end
end

#list_collegesObject



46
47
48
49
50
51
52
53
# File 'lib/university_cli_app/university_cli.rb', line 46

def list_colleges
  puts "Top 50 Colleges & Universities in America for 2018"
  list = University_scraper.school_list
  list.each do |school|
    puts "#{school[:rank]}. #{school[:name]}"
  end
  puts ""
end


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
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/university_cli_app/university_cli.rb', line 7

def menu
  input = nil
  unless input == "3"
    puts "Welcome to the top 50 Colleges & Universities in America for 2018."
    puts ""
    puts "Please select an option and press enter:"
    puts "1. View entire college list"
    puts "2. Select University by rank"
    puts "3. Exit"
    puts ""
  answer = gets.strip

  if answer == "1"
    list_colleges
  elsif answer == "2"
    list_by_rank
  elsif answer ==  "3"
    close_app
  else
    puts "Please try again."
    menu
  end

  puts "Please choose another option and press enter:"
  puts "1. Back to menu"
  puts "2. Exit"
  input = gets.strip

  if input == "1"
    menu
  elsif input == "2"
    close_app
  else
    puts "Please try again."
    menu
  end
  end
end