Class: IntermatScrape::Cli
- Inherits:
-
Object
- Object
- IntermatScrape::Cli
- Defined in:
- lib/intermat_scrape/cli.rb
Instance Method Summary collapse
- #choose_rank(weight_class) ⇒ Object
- #choose_weight ⇒ Object
- #flow ⇒ Object
- #load_data ⇒ Object
- #quit_scraper ⇒ Object
- #restart(weight_class) ⇒ Object
- #start ⇒ Object
- #welcome ⇒ Object
Instance Method Details
#choose_rank(weight_class) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/intermat_scrape/cli.rb', line 76 def choose_rank(weight_class) weight_class.print_wrestlers puts '' puts 'Type one of the following commands:' puts 'a number 1-20'.colorize(:light_cyan).concat(' to view the corresponding wrestler') puts 'back(b):'.colorize(:light_cyan).concat(' return to weight classes') puts 'exit:'.colorize(:light_cyan).concat(' exit program') puts '' command = gets.strip.downcase until %w[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 back b exit].include?(command) puts 'Invalid command. Please enter a valid command.' command = gets.strip.downcase end case command when '1'..'20' weight_class.get_wrestler_by_rank(command).to_s restart(weight_class) when 'back', 'b' start when 'exit' quit_scraper end end |
#choose_weight ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/intermat_scrape/cli.rb', line 37 def choose_weight weight_class = nil puts '' puts 'What weight class are you interested in?' puts '' IntermatScrape::WeightClass.print_weights input = gets.strip until IntermatScrape::WeightClass::WEIGHT_CLASSES.include?(input) puts "I don't recognize that weight class. Please try again." input = gets.strip end weight = IntermatScrape::WeightClass.find_by_weight(input) IntermatScrape::Scraper.create_wrestlers(weight) if weight.wrestlers.empty? puts '' puts 'Type one of the following commands:' puts 'rankings(r):'.colorize(:light_cyan).concat(' show top 20 wrestlers') puts 'back(b):'.colorize(:light_cyan).concat(' return to weight classes') puts 'exit:'.colorize(:light_cyan).concat(' exit program') puts '' command = gets.strip.downcase until %w[rankings r back b exit].include?(command) puts 'Invalid command. Please type a valid command.' command = gets.strip.downcase end case command when 'rankings', 'r' weight_class = IntermatScrape::WeightClass.find_by_weight(input) when 'back', 'b' start when 'exit' quit_scraper end weight_class end |
#flow ⇒ Object
9 10 11 12 13 |
# File 'lib/intermat_scrape/cli.rb', line 9 def flow welcome load_data start end |
#load_data ⇒ Object
2 3 4 5 6 7 |
# File 'lib/intermat_scrape/cli.rb', line 2 def load_data IntermatScrape::WeightClass.create_weight_classes # IntermatScrape::WeightClass.all.each do |weight_class| # IntermatScrape::Scraper.create_wrestlers(weight_class) # end end |
#quit_scraper ⇒ Object
31 32 33 34 35 |
# File 'lib/intermat_scrape/cli.rb', line 31 def quit_scraper puts '' puts 'Thank you for using IntermatScrape!' exit end |
#restart(weight_class) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/intermat_scrape/cli.rb', line 101 def restart(weight_class) puts '' puts 'What would you like to do now?' puts 'view(v):'.colorize(:light_cyan).concat(' view another wrestler from this weight class') puts 'back(b):'.colorize(:light_cyan).concat(' return to weight classes') puts 'exit:'.colorize(:light_cyan).concat(' exit program') puts '' command = gets.strip.downcase until %w[view v back b exit].include?(command) puts 'Invalid command. Please type a valid command.' command = gets.strip.downcase end case command when 'view', 'v' choose_rank(weight_class) when 'back', 'b' start when 'exit' quit_scraper end end |
#start ⇒ Object
25 26 27 28 29 |
# File 'lib/intermat_scrape/cli.rb', line 25 def start if weight_class = choose_weight choose_rank(weight_class) end end |
#welcome ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/intermat_scrape/cli.rb', line 15 def welcome puts '-----------------------------------------------------------------' puts '' puts 'Welcome to IntermatScrape, a way to delve into the top 20 ranked' puts ' NCAA wrestlers.' puts '' puts '' puts '-----------------------------------------------------------------' end |