Class: WikiScraper::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/wiki_scraper/cli.rb

Instance Method Summary collapse

Instance Method Details

#blankObject



2
3
4
# File 'lib/wiki_scraper/cli.rb', line 2

def blank
  puts "\e[2J\e[f"
end

#cliObject



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_messageObject



50
51
52
53
54
55
56
57
58
# 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_choiceObject



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

#lineObject



6
7
8
# File 'lib/wiki_scraper/cli.rb', line 6

def line
  puts "----------------------------------------------"
end

#loadingObject



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_searchObject



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_loopObject



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
      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_menuObject



45
46
47
48
# File 'lib/wiki_scraper/cli.rb', line 45

def return_to_menu
  puts "Press enter to return"
  gets
end

#timeObject

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

#welcomeObject



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