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
7
8
9
10
# File 'lib/poll_tracker/cli.rb', line 4

def call
  welcome 
  show_score(PollTracker::Scraper.avg_results_hash)
  menu
  list_polls
  show_poll
end

#list_pollsObject



50
51
52
# File 'lib/poll_tracker/cli.rb', line 50

def list_polls
  puts PollTracker::Scraper.poll_names_index
end


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/poll_tracker/cli.rb', line 12

def menu
  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."
  input = nil
  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

#show_pollObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/poll_tracker/cli.rb', line 54

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

#show_score(score) ⇒ Object



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

def show_score(score) 
  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)
end

#welcomeObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/poll_tracker/cli.rb', line 31

def welcome
  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)
end