Class: MovieRecommender::CLI
- Inherits:
-
Object
- Object
- MovieRecommender::CLI
- Defined in:
- lib/movie_recommender/cli.rb
Constant Summary collapse
- @@location =
[]
Instance Attribute Summary collapse
-
#scraper ⇒ Object
Returns the value of attribute scraper.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #list_movies ⇒ Object
- #location_prompt ⇒ Object
- #postalcode_prompt ⇒ Object
- #prompt_user ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
6 7 |
# File 'lib/movie_recommender/cli.rb', line 6 def initialize end |
Instance Attribute Details
#scraper ⇒ Object
Returns the value of attribute scraper.
2 3 4 |
# File 'lib/movie_recommender/cli.rb', line 2 def scraper @scraper end |
Class Method Details
.all ⇒ Object
88 89 90 |
# File 'lib/movie_recommender/cli.rb', line 88 def self.all @@location end |
.clear ⇒ Object
92 93 94 |
# File 'lib/movie_recommender/cli.rb', line 92 def self.clear @@location.clear end |
Instance Method Details
#list_movies ⇒ Object
41 42 43 44 45 46 47 |
# 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 ⇒ Object
33 34 35 36 37 38 39 |
# 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 ⇒ Object
26 27 28 29 30 31 |
# 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 ⇒ Object
49 50 51 52 53 54 55 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 82 |
# 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 ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# 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 |