class BestMovies::CLI

Constants

BASE_PATH

Public Instance Methods

add_info() click to toggle source
# File lib/best_movie_year/cli.rb, line 32
def add_info
  puts "Would you like more information? (Y/N)"
  input = gets.strip
  if input.downcase == "y"
    puts ""
    print_desc
    puts ""
    diff_year
  elsif input.downcase == "n"
    puts ""
    diff_year
  else
    puts ""
    puts "Invalid entry. Please enter Y or N"
    puts ""
    print_movies
  end
end
call() click to toggle source
# File lib/best_movie_year/cli.rb, line 5
def call
  puts "Welcome!"
  start
end
diff_year() click to toggle source
# File lib/best_movie_year/cli.rb, line 51
def diff_year
  puts "Would you like to enter a different year? (Y/N)"
  input = gets.strip
  if input.downcase == "n"
    puts ""
    puts "Goodbye."
  elsif input.downcase == "y"
    puts ""
    BestMovies::Movie.reset_all
    start
  else
    puts "Invalid entry. Please enter Y or N."
    puts ""
    diff_year
  end
end
make_movies(input) click to toggle source
# File lib/best_movie_year/cli.rb, line 10
def make_movies(input)
  movie_array = BestMovies::Movie.scrape_movies(BASE_PATH + "/top/bestofrt/?year=" + input)
  BestMovies::Movie.create(movie_array)
end
print_desc() click to toggle source
print_movies() click to toggle source
start() click to toggle source
# File lib/best_movie_year/cli.rb, line 68
def start
  puts "Please enter a four-digit year from 1950 to 2018 to view the top 10 movies of that year. To exit, please type 'EXIT':"
  input = gets.strip
  if input.to_i >= 1950 && input.to_i <= 2018
    make_movies(input)
    puts ""
    puts "Top 10 Movies of #{input.to_i}"
    print_movies
  elsif input.downcase == "exit"
    puts ""
    puts "Goodbye."
  else
    puts ""
    puts "Invalid entry."
    puts ""
    start
  end
end
wrap(s, width=73) click to toggle source
# File lib/best_movie_year/cli.rb, line 87
def wrap(s, width=73)
  s.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n")
end