Class: CLI
- Inherits:
-
Object
- Object
- CLI
- Defined in:
- lib/NBA_news/cli.rb
Instance Method Summary collapse
Instance Method Details
#list_stories ⇒ Object
14 15 16 17 18 |
# File 'lib/NBA_news/cli.rb', line 14 def list_stories Story.all.each_with_index do |story, i| puts "#{i+1}) #{story.title.colorize(:blue)} By: #{story.}" end end |
#menu ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/NBA_news/cli.rb', line 21 def response = gets.strip.downcase if response == "y" || response == "yes" puts "What story would you like to read? (Select a number or 'exit'.)".colorize(:yellow) input = gets.strip.downcase if input.to_i.between?(1, Story.all.size) story_object = Story.all[input.to_i-1] Scraper.scrape_content(story_object.url) elsif input.to_i.between?(1, Story.all.size) == false && input != "exit" puts "I'm sorry that story is not listed.".colorize(:yellow) sleep 1 list_stories puts "Please choose a story number that is listed or 'exit' to close.".colorize(:yellow) else input == "exit" puts "Thanks for visiting, goodbye!".colorize(:yellow) end elsif response == "n" || response == "no" puts "Okay, maybe next time. Thanks for stopping by!".colorize(:yellow) else puts "I'm sorry, I did not get that. Please respond with a 'yes' or 'no'".colorize(:yellow) end end |
#rerun_menu ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/NBA_news/cli.rb', line 49 def input = gets.strip.downcase if input.to_i.between?(1, Story.all.size) story_object = Story.all[input.to_i-1] Scraper.scrape_content(story_object.url) elsif input.to_i.between?(1, Story.all.size) == false && input != "exit" puts "I'm sorry that story is not listed.".colorize(:yellow) sleep 1 list_stories puts "Please choose a story number that is listed or 'exit' to close.".colorize(:yellow) else input == "exit" puts "Thanks for visiting, goodbye!".colorize(:yellow) end end |
#run ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/NBA_news/cli.rb', line 3 def run puts "Welcome to NBA News! Here are the latest stories around the league:".colorize(:yellow) sleep 1 Scraper.scrape list_stories sleep 1 puts "Would you like to read a story? [y/n]".colorize(:yellow) end |
#second_menu ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/NBA_news/cli.rb', line 67 def puts "Would you like to read another story? [y/n]".colorize(:yellow) answer = gets.strip.downcase if answer == "y" || answer =="yes" list_stories puts "Great! Please make another selection. (Enter story number)".colorize(:yellow) elsif answer == "n" || answer == "no" puts "Thanks for reading, goodbye!".colorize(:yellow) else puts "I'm sorry. I did not get that.".colorize(:yellow) end end |