Class: LesserEvil::CommandLineInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/lesser_evil/command_line_interface.rb

Instance Method Summary collapse

Constructor Details

#initializeCommandLineInterface

Returns a new instance of CommandLineInterface.



3
4
# File 'lib/lesser_evil/command_line_interface.rb', line 3

def initialize
end

Instance Method Details

#callObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/lesser_evil/command_line_interface.rb', line 43

def call

   intro_display
   exit = nil

   while !exit do
    print "Trump or Clinton? Choose a candidate: "
    candidate = input_validation(['trump','clinton'])
    print "Angry or very angry? "
    very_angry = input_validation(['angry','very angry']) == 'very angry'
    puts "\n\n"
    tweets = LesserEvil::TweetController.new(candidate: candidate, is_intense: very_angry, sentiment: "Negative", fast_print: true).get_print_tweets
    puts "\n\n"
    print "New batch? (yes/no): "
    exit = input_validation(['y','yes','n','no']).start_with?('n')
  end

  puts "O.K.! Take it easy."

end

#input_validation(valid_array) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/lesser_evil/command_line_interface.rb', line 34

def input_validation(valid_array)
  input = gets.chomp.downcase
  while !valid_array.include?(input) do
    print "\nInvalid input. Try again. "
    input = gets.chomp.downcase
  end
  input
end

#intro_displayObject



6
7
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
# File 'lib/lesser_evil/command_line_interface.rb', line 6

def intro_display
  50.times { puts }

  File.open(File.join(File.dirname(__FILE__), "/../assets/hillary.txt"), "r") do |file|
    file.readlines.each do |line|
      print line.white.on_black
      sleep 0.05
    end
  end

  puts "\n\n" 
  

  File.open(File.join(File.dirname(__FILE__), "/../assets/donald.txt"), "r") do |file|
    file.readlines.each do |line|
      print line.white.on_black
      sleep 0.05
    end
  end

  puts "\n\n"
  puts "-----------------------------------".red
  puts "LESSER EVIL  ••••••••••••••••••••••".red
  puts
  puts "Peruse the angriest election tweets".red
  puts "-----------------------------------\n\n\n".red
end