class MovieRecommender::CLI
Attributes
scraper[RW]
Public Class Methods
all()
click to toggle source
# File lib/movie_recommender/cli.rb, line 88 def self.all @@location end
clear()
click to toggle source
# File lib/movie_recommender/cli.rb, line 92 def self.clear @@location.clear end
new()
click to toggle source
# File lib/movie_recommender/cli.rb, line 6 def initialize end
Public Instance Methods
list_movies()
click to toggle source
# File lib/movie_recommender/cli.rb, line 41 def list_movies scraper = MovieRecommender::Scraper.new scraper.scrape_movies.each.with_index(1) do |movie, index| puts "#{index}. #{movie.title}" end prompt_user end
location_prompt()
click to toggle source
# File lib/movie_recommender/cli.rb, line 33 def location_prompt puts "Please enter your location from the following list" puts "AR, AU, CA, CL, DE, ES, FR, IT, MX, NZ, PT, UK, US" input = gets.strip @@location << input list_movies end
postalcode_prompt()
click to toggle source
# File lib/movie_recommender/cli.rb, line 26 def postalcode_prompt puts "Please enter the postal code of your location" input = gets.strip @@location << input location_prompt end
prompt_user()
click to toggle source
# File lib/movie_recommender/cli.rb, line 49 def prompt_user puts "*************************************" puts "Enter the number of the movie you want to check the detail." puts "Input [exit] to quit." puts "*************************************" input = "" while input.downcase != "exit" input = gets.strip actual_input = input.to_i-1 if input.to_i != 0 && input.to_i <= MovieRecommender::Movie.all.size url = MovieRecommender::Movie.all[actual_input].url title = MovieRecommender::Movie.all[actual_input].title scraper = MovieRecommender::Scraper.new scraper.scrape_details(url) score = scraper.score description = scraper.description puts "*******#{title} |IMDB:#{score}|*******" puts "***************SUMMARY***************" puts description puts "*************************************" puts "Enter the number of the movie you want to check the detail." puts "Input [exit] to quit." puts "*************************************" elsif input.downcase == "exit" puts "See you next time." exit else puts "Invaild input. Please try again." end end end
start()
click to toggle source
# File lib/movie_recommender/cli.rb, line 9 def start puts "Hi! Welcome to MovieRecommender" puts "Do you want to want to list movies currently in theaters near to your location?" puts "**Input [Y] to continue or input [N] to exit**" input = gets.strip if input.downcase == "y" postalcode_prompt elsif input.downcase == "n" exit else puts "Invaild input!" start end end