Class: WikiScraper::CLI
- Inherits:
-
Object
- Object
- WikiScraper::CLI
- Defined in:
- lib/wiki_scraper/cli.rb
Instance Method Summary collapse
- #blank ⇒ Object
- #cli ⇒ Object
- #exit_message ⇒ Object
- #get_subheading_choice ⇒ Object
- #line ⇒ Object
- #loading ⇒ Object
- #page_search ⇒ Object
- #program_loop ⇒ Object
- #return_to_menu ⇒ Object
-
#time ⇒ Object
This is for testing to speed things up.
- #welcome ⇒ Object
Instance Method Details
#blank ⇒ Object
2 3 4 |
# File 'lib/wiki_scraper/cli.rb', line 2 def blank puts "\e[2J\e[f" end |
#cli ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/wiki_scraper/cli.rb', line 82 def cli welcome search_term = page_search.strip.gsub(" ", "_") loading page = WikiScraper::Scraper.new.get_page(search_term) @article = WikiScraper::WikiDisplay.new(page) puts @running = true program_loop if @search_again cli end end |
#exit_message ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/wiki_scraper/cli.rb', line 50 def blank line line puts " Have a great day!" line line sleep(time) end |
#get_subheading_choice ⇒ Object
40 41 42 43 |
# File 'lib/wiki_scraper/cli.rb', line 40 def get_subheading_choice puts "Make a selection: (1-#{@article.subheading_count + 2})" input = gets.strip.to_i - 1 end |
#line ⇒ Object
6 7 8 |
# File 'lib/wiki_scraper/cli.rb', line 6 def line puts "----------------------------------------------" end |
#loading ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/wiki_scraper/cli.rb', line 27 def loading 10.times do |index| blank puts "Loading#{"." * (index + 1)}" sleep(0.05) end end |
#page_search ⇒ Object
35 36 37 38 |
# File 'lib/wiki_scraper/cli.rb', line 35 def page_search puts "Enter a term and we will attempt to retrieve the page" gets end |
#program_loop ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/wiki_scraper/cli.rb', line 60 def program_loop while @running blank @article.print_trio input = get_subheading_choice if input == @article.subheading_count + 1 @running = false @search_again = false elsif input == @article.subheading_count @running = false @search_again = true elsif input > @article.subheading_count + 1 or input < 0 puts "Invalid Input. Try Again" sleep(1) else @article.print_topic(input) end end end |
#return_to_menu ⇒ Object
45 46 47 48 |
# File 'lib/wiki_scraper/cli.rb', line 45 def puts "Press enter to return" gets end |
#time ⇒ Object
This is for testing to speed things up
10 11 12 |
# File 'lib/wiki_scraper/cli.rb', line 10 def time #This is for testing to speed things up 2.5 end |
#welcome ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/wiki_scraper/cli.rb', line 14 def welcome blank line puts " Welcome To WikiScraper! #{WikiScraper::VERSION}" line sleep(1.5) blank line puts "Let's search for an article:" line sleep(1.5) end |