class WikiScraper::CLI

Public Instance Methods

blank() click to toggle source
# File lib/wiki_scraper/cli.rb, line 2
def blank
  puts "\e[2J\e[f"
end
cli() click to toggle source
# 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() click to toggle source
# File lib/wiki_scraper/cli.rb, line 50
def exit_message
  blank
  line
  line
  puts "             Have a great day!"
  line
  line
  sleep(time)
end
get_subheading_choice() click to toggle source
# 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() click to toggle source
# File lib/wiki_scraper/cli.rb, line 6
def line
  puts "----------------------------------------------"
end
loading() click to toggle source
# File lib/wiki_scraper/cli.rb, line 27
def loading
  10.times do |index|
    blank
    puts "Loading#{"." * (index + 1)}"
    sleep(0.05)
  end
end
program_loop() click to toggle source
# 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
      exit_message
      @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)
      return_to_menu
    end
  end
end
return_to_menu() click to toggle source
# File lib/wiki_scraper/cli.rb, line 45
def return_to_menu
  puts "Press enter to return"
  gets
end
time() click to toggle source
# File lib/wiki_scraper/cli.rb, line 10
def time #This is for testing to speed things up
  2.5
end
welcome() click to toggle source
# 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