Class: BoxOffice::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/box_office/cli.rb

Instance Method Summary collapse

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
45
46
# File 'lib/box_office/cli.rb', line 29

def display_movie_info(user_input)
  movie = BoxOffice::Movie.all[user_input]
  puts "---"
  puts "#{movie.title}".colorize(:red)
  puts "#{movie.synopsis}" if movie.synopsis != ""
  puts "" if movie.synopsis != ""
  puts "Genres:".colorize(:blue) + " #{movie.genres}" if !movie.genres.nil?
  puts "Rating:".colorize(:blue) + " #{movie.rating}" if !movie.rating.nil?
  puts "Studio:".colorize(:blue) + " #{movie.studio}" if !movie.studio.nil?
  puts "Director:".colorize(:blue) + " #{movie.director}" if !movie.director.nil?
  puts "Writers:".colorize(:blue) + " #{movie.writers}" if !movie.writers.nil?
  puts "Cast:".colorize(:blue) + " #{movie.cast}" if movie.cast != ""
  puts "Release Date:".colorize(:blue) + " #{movie.release_date}" if !movie.release_date.nil?
  puts "Runtime:".colorize(:blue) + " #{movie.runtime}" if !movie.runtime.nil?
  puts "Critic Score:".colorize(:blue) + " #{movie.critic_score}"
  puts "Audience Score:".colorize(:blue) + " #{movie.audience_score}"
  puts "---"
end

#goodbyeObject



64
65
66
# File 'lib/box_office/cli.rb', line 64

def goodbye
  puts "Peace out homie!".colorize(:green) + " <3".colorize(:light_red)
end

#greetingObject



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!".colorize(:green)
end

#list_moviesObject



14
15
16
17
18
19
20
21
# File 'lib/box_office/cli.rb', line 14

def list_movies
  puts "---"
  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 "---"
end


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/box_office/cli.rb', line 48

def menu
  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:".colorize(:green)
    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

#runObject



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
  menu
  goodbye
end