Class: BestMovies::CLI
- Inherits:
-
Object
- Object
- BestMovies::CLI
- Defined in:
- lib/best_movie_year/cli.rb
Constant Summary collapse
- BASE_PATH =
"https://www.rottentomatoes.com"
Instance Method Summary collapse
- #add_info ⇒ Object
- #call ⇒ Object
- #diff_year ⇒ Object
- #make_movies(input) ⇒ Object
- #print_desc ⇒ Object
- #print_movies ⇒ Object
- #start ⇒ Object
- #wrap(s, width = 73) ⇒ Object
Instance Method Details
#add_info ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# 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 ⇒ Object
5 6 7 8 |
# File 'lib/best_movie_year/cli.rb', line 5 def call puts "Welcome!" start end |
#diff_year ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# 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) ⇒ Object
10 11 12 13 |
# 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 ⇒ Object
25 26 27 28 29 30 |
# File 'lib/best_movie_year/cli.rb', line 25 def print_desc BestMovies::Movie.all.first(10).each.with_index(1) { |movie, i| puts "#{i}. #{wrap(movie.title[:desc][:desc])}" puts "" } end |
#print_movies ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/best_movie_year/cli.rb', line 15 def print_movies BestMovies::Movie.all.first(10).each.with_index(1) { |movie, i| puts "#{i}. #{movie.title[:title]}" url = "#{movie.title[:url]}" BestMovies::Movie.scrape_desc(url) } puts "" add_info end |
#start ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# 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) ⇒ Object
87 88 89 |
# File 'lib/best_movie_year/cli.rb', line 87 def wrap(s, width=73) s.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n") end |