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
# 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.rating}"
  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

#goodbyeObject



62
63
64
# File 'lib/box_office/cli.rb', line 62

def goodbye
  puts "Peace out homie! <3"
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!"
end

#list_moviesObject



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


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

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:"
    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