Class: PollTracker::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



4
5
6
# File 'lib/poll_tracker/cli.rb', line 4

def call
  welcome 
end

#list_pollsObject



42
43
44
# File 'lib/poll_tracker/cli.rb', line 42

def list_polls
  puts PollTracker::Scraper.poll_names_index
end

#show_pollObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/poll_tracker/cli.rb', line 46

def show_poll  
  puts "Please choose the number of the poll you would like to see."
  puts "Enter a number between 1-25"

  poll_number = gets.strip
  poll_number = poll_number.to_i - 1
  if poll_number.between?(0, 24)
    @poll = PollTracker::Poll.new_poll(poll_number)
    puts ""
    puts "Poll Source:-------------#{@poll.name}" 
    puts "Hillary Clinton: --------#{@poll.clinton}%"
    puts "Donald Trump: -----------#{@poll.trump}%"
    puts "Lead: -------------------#{@poll.lead} Points"
    puts "Dates Polled: -----------#{@poll.date}"
    puts "Likely Voters Polled: ---#{@poll.polled}"
    puts ""
    puts "Type 'YesHillary' or 'NeverTrump' to see go back to list."
    puts "Or type 'exit' to leave"

  elsif
    puts "That is not a valid selection. Please type 'NeverTrump' or 'YesHillary' and choose again"
  end    
end

#welcomeObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/poll_tracker/cli.rb', line 8

def welcome
  input = nil
  puts "***********POLL TRACKER 2016!! TRUMP vs CLINTON!!***********".white.on_light_red
  puts "*****************THE SHAMING OF AMERICA!!!!*****************".white.on_light_red
  puts ""
  sleep(1.5 )
  puts "----Hello! I am Poll Tracker! I can show you many polls.----".blue.on_light_white
  puts "----Currently, the average of more than 350 polls shows:----".blue.on_light_white
  puts ""
  sleep(1.5)
  score = PollTracker::Scraper.avg_results_hash
  puts "*****HILLARY CLINTON***** =====> #{score[:clinton]}%**********************".light_white.on_light_blue.underline
  puts "*****DONALD TRUMP?******* =====> #{score[:trump]}%*********** Seriously?".light_white.on_light_blue
  puts "" 
  sleep(1.5)
  puts "Type 'YesHillary' or 'NeverTrump' to see a list of the 25 most recent polls."
  puts "Type 'exit' if this makes you sick and want to leave. PollTracker understands."

  while input != "exit" 
  input = gets.strip.downcase
    
    if input.downcase == "nevertrump" || input.downcase == "yeshillary"
      list_polls
      show_poll     
    else 
      puts "Rigged! Try again, type 'NeverTrump' or 'YesHillary'. Otherwise, type exit and leave!"       
    end
    if input.downcase == "exit"
      puts "Goodbye. Vote Quimby!"
    end
  end
end