Class: RtTop100::CLI

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

Instance Method Summary collapse

Instance Method Details

#add_movie_details(selected_movie) ⇒ Object



96
97
98
99
# File 'lib/rt_top_100/cli.rb', line 96

def add_movie_details(selected_movie)
    details_hash = RtTop100::Scraper.scrape_movie("https://www.rottentomatoes.com#{selected_movie.movie_url}")
    selected_movie.add_details(details_hash)
end

#callObject



3
4
5
6
7
8
9
10
# File 'lib/rt_top_100/cli.rb', line 3

def call
  puts ""
  puts "********* Best of Rotten Tomatoes: TOP 100 MOVIES OF ALL TIME *********"
  puts ""
  puts "Welcome cinephile! Which of Rotten Tomatoes' Top 100 Movies would you like to see?"
  create_movies
  start
end

#create_moviesObject



12
13
14
# File 'lib/rt_top_100/cli.rb', line 12

def create_movies
  RtTop100::Scraper.scrape_top_100("https://www.rottentomatoes.com/top/bestofrt/")
end

#display_movie_details(selected_movie) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/rt_top_100/cli.rb', line 101

def display_movie_details(selected_movie)
    puts ""
    puts "********* Best of Rotten Tomatoes: #{selected_movie.title} *********"
    puts ""
    puts "Title:  #{selected_movie.title}"
    puts ""
    puts "Tomatometer Score: #{selected_movie.tomatometer_score}"
    puts "Audience Score: #{selected_movie.audience_score}"
    puts "Critic Consensus: #{selected_movie.critic_consensus}"
    puts ""
    puts "Rated: #{selected_movie.rating}"
    puts "Genre: #{selected_movie.genre}"
    puts "Released: #{selected_movie.release_date}"
    puts "Directed by: #{selected_movie.director}"
    puts ""
    puts "Synopsis: #{selected_movie.synopsis}"
    puts ""
end

#display_movies(input) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rt_top_100/cli.rb', line 65

def display_movies(input)
    if input == "1-25" || input == "26-50" || input == "51-75" || input == "76-100"
      puts ""
      puts "********* Best of Rotten Tomatoes: TOP MOVIES OF ALL TIME #{input} *********"
      puts ""
      list_from = input.to_i
      RtTop100::Movie.all[list_from-1, 25].each.with_index(list_from) do | movie, rank |
        puts "#{rank}. #{movie.title}"
      end
    elsif input.to_i.between?(1920, Date.today.year)
      puts ""
      puts "********* Best of Rotten Tomatoes: TOP MOVIES RELEASED IN OR AFTER #{input} *********"
      puts ""
      year = input.to_i
      RtTop100::Movie.movies_release_after(year)
    elsif input == "methodology"
      puts ""
      puts "Methodology: Each critic from Rotten Tomatoes' discrete list gets one vote, weighted equally. A movie must have 40 or more rated reviews to be considered. The 'Adjusted Score' comes from a weighted formula (Bayesian) that we use that accounts for variation in the number of reviews per movie."
      puts ""
      start
    elsif input == "exit"
      puts ""
      puts "The End. Thank you!"
      puts ""
      exit
    else
      puts "I'm not quite sure what you meant."
      start
  end
end

#startObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rt_top_100/cli.rb', line 16

def start
  puts ""
  puts "Please select from the following options:"
  puts "To see the top 100 movies, enter '1-25', '26-50', '51-75', or '76-100'"
  puts "To see all the movies on the list released after a given year (starting in 1920), enter the year"
  puts "To see the methodology behind the list, enter 'methodology'"
  puts "To exit the program, enter 'exit'"
  puts ""
  input = gets.strip.downcase

  display_movies(input)

  puts ""
  puts "To learn more about a specific movie, please enter the movie's rank. You can also enter 'main' to return to the main menu or 'exit' to exit the program."
  input = gets.strip.downcase


  if input.to_i.between?(1,100)
    selected_movie = RtTop100::Movie.all[input.to_i-1]
    add_movie_details(selected_movie)
    display_movie_details(selected_movie)
  elsif input == "main"
    start
  elsif input == "exit"
    exit
  else
    puts "I'm not quite sure what you meant."
    start
  end

  puts ""
  puts "Would you like to see more movies? Y/N"
  puts ""
  input = gets.strip.downcase
    if input == "y"
      start
    elsif input == "n"
      puts ""
      puts "The End. Thank you!"
      puts ""
      exit
    else
      puts ""
      puts "I'm not quite sure what you meant."
      puts ""
      start
    end
end