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



43
44
45
46
47
# File 'lib/box_office/cli.rb', line 43

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



49
50
51
52
53
# File 'lib/box_office/cli.rb', line 49

def display_movie_info(user_input)
  movie = BoxOffice::Movie.all[user_input]
  movie.print_info
  puts "---"
end

#goodbyeObject



55
56
57
# File 'lib/box_office/cli.rb', line 55

def goodbye
  puts "Peace out homie!".colorize(:cyan) + " <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)
  BoxOffice::Movie.all.each_with_index do |movie, i|
    puts "#{i + 1}.".colorize(:blue) + " #{movie.title}, #{movie.earnings}"
  end
  puts "---"
end


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/box_office/cli.rb', line 23

def menu
  input = nil
  until input == "exit"
    puts "What do you want to do?".colorize(:green)
    puts "* Enter ".colorize(:green) + "movie number".colorize(:blue) + " to learn more about the movie".colorize(:green)
    puts "* Type '".colorize(:green) + "list".colorize(:blue) + "' to see the list again".colorize(:green)
    puts "* Type '".colorize(:green) + "exit".colorize(:blue) + "' to leave the app".colorize(:green)
    puts "---"
    input = gets.strip.downcase
    if input.to_i.between?(1, BoxOffice::Movie.all.length)
      add_attributes_to_movie(input.to_i - 1) if BoxOffice::Movie.all[input.to_i - 1].rating.nil? # Only scrapes webpage if attributes are 'nil' to prevent scraping multiple times
      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