class ApprovalRatings::CLI

Public Instance Methods

call() click to toggle source
# File lib/approval_ratings/cli.rb, line 3
def call
  start
end
list() click to toggle source
# 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
print_rating(rating) click to toggle source
print_rating_i(rating) click to toggle source
start() click to toggle source
# 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