Class: BoxOffice::CLI
- Inherits:
-
Object
- Object
- BoxOffice::CLI
- Defined in:
- lib/box_office/cli.rb
Instance Method Summary collapse
- #add_attributes_to_movie(user_input) ⇒ Object
- #display_movie_info(user_input) ⇒ Object
- #goodbye ⇒ Object
- #greeting ⇒ Object
- #list_movies ⇒ Object
- #menu ⇒ Object
- #run ⇒ Object
Instance Method Details
#add_attributes_to_movie(user_input) ⇒ Object
23 24 25 26 27 |
# File 'lib/box_office/cli.rb', line 23 def add_attributes_to_movie(user_input) movie = BoxOffice::Movie.all[user_input] attributes = BoxOffice::Scraper.scrape_movie_page(user_input) movie.add_movie_attributes(attributes) end |
#display_movie_info(user_input) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/box_office/cli.rb', line 29 def display_movie_info(user_input) movie = BoxOffice::Movie.all[user_input] puts "---".colorize(:green) puts "#{movie.title}".colorize(:red) puts "#{movie.synopsis}" puts "" puts "Genres:".colorize(:blue) + " #{movie.genres}" puts "Rating:".colorize(:blue) + " #{movie.}" puts "Director:".colorize(:blue) + " #{movie.director}" puts "Writers:".colorize(:blue) + " #{movie.writers}" puts "Cast:".colorize(:blue) + " #{movie.cast}" puts "Critic Score:".colorize(:blue) + " #{movie.critic_score}" puts "Audience Score:".colorize(:blue) + " #{movie.audience_score}" puts "---".colorize(:green) end |
#goodbye ⇒ Object
62 63 64 |
# File 'lib/box_office/cli.rb', line 62 def goodbye puts "Peace out homie! <3" end |
#greeting ⇒ Object
10 11 12 |
# File 'lib/box_office/cli.rb', line 10 def greeting puts "Greetings and salutations, moviegoer! Here's last weekend's box office results!" end |
#list_movies ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/box_office/cli.rb', line 14 def list_movies puts "---".colorize(:green) puts "Last Weekend's Box Office:".colorize(:red) @movies_list.each_with_index do |(movie, earnings), i| puts "#{i + 1}.".colorize(:blue) + " #{movie}, #{earnings}" end puts "---".colorize(:green) end |
#menu ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/box_office/cli.rb', line 46 def input = nil until input == "exit" puts "Enter movie number to see more info, 'list' to see the list again, or 'exit' to leave the app:" input = gets.strip.downcase if input.to_i.between?(1, BoxOffice::Movie.all.length) add_attributes_to_movie(input.to_i - 1) display_movie_info(input.to_i - 1) elsif input == "list" list_movies elsif input != "exit" puts "Whoops, please try again!".colorize(:red) end end end |
#run ⇒ Object
2 3 4 5 6 7 8 |
# File 'lib/box_office/cli.rb', line 2 def run greeting @movies_list = BoxOffice::Scraper.scrape_movie_list # Generates movie list right away to avoid scraping list multiple times list_movies goodbye end |