Class: NewMovies::CLI
- Inherits:
-
Object
- Object
- NewMovies::CLI
- Defined in:
- lib/new_movies/CLI.rb
Constant Summary collapse
- WIDTH =
70
Instance Method Summary collapse
- #call ⇒ Object
- #center(string, c = "-") ⇒ Object
- #goodbye ⇒ Object
- #list_new_movies ⇒ Object
- #main_menu ⇒ Object
- #menu ⇒ Object
- #menu_restart ⇒ Object
- #movie_details(input) ⇒ Object
- #wrap(s) ⇒ Object
Instance Method Details
#call ⇒ Object
18 19 20 21 |
# File 'lib/new_movies/CLI.rb', line 18 def call NewMovies::Scraper.scrape_coming_soon_movies end |
#center(string, c = "-") ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/new_movies/CLI.rb', line 5 def center(string, c = "-") string = " #{string} " if string != "" until string.length >= WIDTH string.prepend(c) string << (c) end string.prepend("\n") end |
#goodbye ⇒ Object
85 86 87 88 |
# File 'lib/new_movies/CLI.rb', line 85 def goodbye puts "See you next time!" exit end |
#list_new_movies ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/new_movies/CLI.rb', line 23 def list_new_movies puts center("MOVIES COMING SOON TO CINEMARK THEATRES") puts " " NewMovies::Movie.all.each_with_index do |movie, index| puts " #{index+1}. #{movie.title}" if index.to_i+1 < 10 puts " #{index+1}. #{movie.title}" if index.to_i+1 >= 10 end puts center("END OF LIST") puts " " end |
#main_menu ⇒ Object
50 51 52 53 54 |
# File 'lib/new_movies/CLI.rb', line 50 def list_new_movies puts "Which movie do you want more details about?" end |
#menu ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/new_movies/CLI.rb', line 34 def print "Please select a number: " input = gets.strip.downcase if input == "exit" goodbye elsif input.to_i > 0 && input.to_i <= NewMovies::Movie.all.length movie_details(input) elsif input == "list" else puts "Invalid entry." end end |
#menu_restart ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/new_movies/CLI.rb', line 56 def puts " " print "Enter 'list' to view the movies again or enter 'exit': " input = gets.strip.downcase if input == "exit" goodbye elsif input == "list" else end end |
#movie_details(input) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/new_movies/CLI.rb', line 69 def movie_details(input) details = NewMovies::Movie.find_movie_by_index(input) puts center("#{details.title.upcase}") puts " " puts " URL: #{details.url}" if details.url puts " Runtime: #{details.runtime}" if details.runtime puts " Rating: #{details.}" if details. != "" puts " Genre: #{details.genre}" if details.genre puts " Release Date: #{details.release_date}" if details.release_date puts " Director: #{details.director}" if details.director puts wrap(" Cast: #{details.cast}") if details.cast puts wrap("\n Synopsis: #{details.synopsis}") if details.synopsis puts " Movie Site: #{details.movie_site}" if details.movie_site puts center("END OF DETAILS") end |
#wrap(s) ⇒ Object
14 15 16 |
# File 'lib/new_movies/CLI.rb', line 14 def wrap(s) s.gsub(/(.{1,#{WIDTH}})(\s+|\Z)/, "\\1\n ") end |