Class: ApprovalRatings::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



3
4
5
# File 'lib/approval_ratings/cli.rb', line 3

def call
  start
end

#listObject



7
8
9
10
11
12
13
14
15
# File 'lib/approval_ratings/cli.rb', line 7

def list
  puts ""
  puts "************* President Trump Approval Ratings *************"
  puts ""
  ApprovalRatings::Rating.all.each.with_index(1) do |rating, i|
    puts "#{i}. #{rating.name} on #{rating.date}" 
  end
  puts ""
end


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/approval_ratings/cli.rb', line 17

def print_rating(rating)
  rating.each do |rating|

    puts ""
    puts "-------------- #{rating.name} --------------"
    puts "poll date"      
    puts rating.date
    puts ""
    puts "pollster grade"
    puts rating.summary
    puts ""
    puts "approval rating"
    puts rating.approval
    puts ""
    puts "disapproval rating"
    puts rating.disapproval
    puts ""
  end
end


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/approval_ratings/cli.rb', line 37

def print_rating_i(rating)   

    puts ""
    puts "-------------- #{rating.name} --------------"      
    puts "poll date"      
    puts rating.date
    puts ""
    puts "pollster grade"
    puts rating.summary
    puts ""
    puts "approval rating"
    puts rating.approval
    puts ""
    puts "disapproval rating"
    puts rating.disapproval
    puts ""
  
end

#startObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/approval_ratings/cli.rb', line 56

def start
  list
  input = nil
  while input != "exit"
    puts ""
    puts "What poll would you more information on, by name or number?"
    puts ""
    puts "Enter list to see the polls again."
    puts "Enter exit to end the program."
    puts ""
    input = gets.strip
    if input == "list"
      list
    elsif input.to_i == 0
      if rating = ApprovalRatings::Rating.find_by_name(input)          
        print_rating(rating)
        
      end 
    elsif input.to_i > 0
      if rating = ApprovalRatings::Rating.find(input.to_i)
        print_rating_i(rating)
      end
    end
  end
  puts "Goodbye!!!"
end