Class: MovieHelper::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



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

def call
  greeting
  list_options
  satisfaction_check
  goodbye
end

#display(movie) ⇒ Object



134
135
136
137
138
139
140
141
142
# File 'lib/movie_helper/cli.rb', line 134

def display(movie)
  puts "Title: #{movie.title} (#{movie.year})"
  puts "Summary: #{movie.summary}"
  puts "Genre: #{movie.genre}"
  puts "Mood: #{movie.mood}"
  puts "Movie actors: #{movie.actors}"
  puts "Movie director: #{movie.director}"
  puts "Language: #{movie.language}"
end

#goodbyeObject



167
168
169
# File 'lib/movie_helper/cli.rb', line 167

def goodbye
  puts "Thank you for your using Movie Helper!"
end

#greetingObject



10
11
12
13
# File 'lib/movie_helper/cli.rb', line 10

def greeting
  puts "Welcome to Movie Helper!"
  puts
end

#information(movies) ⇒ Object



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

def information(movies)
  puts ""
  puts "For more information on one of these movies, please type 1 - #{movies.count}."
  puts "To return to the main menu, please type 'list'"

  input = gets.chomp
  if input.to_i.between?(1, movies.count)
    input = input.to_i - 1
    more_info(movies[input])
  elsif input == "list"
    list_options
  else
    information(movies)
  end
end

#latest_amazonObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/movie_helper/cli.rb', line 73

def latest_amazon
  if MovieHelper::Movie.latest_amazon.empty?
    puts "Loading..."
    latest_amazon_films = MovieHelper::Scraper.latest_amazon
    MovieHelper::Movie.create_from_list(latest_amazon_films)
    puts ""
  end
  puts "Here are our latest Amazon films:"
  movies = MovieHelper::Movie.latest_amazon
  movies.each.with_index do |movie, i|
    puts "#{i+1}. #{movie.title}"
  end
  information(movies)
end

#latest_elsewhereObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/movie_helper/cli.rb', line 88

def latest_elsewhere
  if MovieHelper::Movie.latest_elsewhere.empty?
    puts "Loading..."
    latest_elsewhere_films = MovieHelper::Scraper.latest_elsewhere
    MovieHelper::Movie.create_from_list(latest_elsewhere_films)
    puts ""
  end
  puts "Here are our latest films:"
  movies = MovieHelper::Movie.latest_elsewhere
  movies.each.with_index do |movie, i|
    puts "#{i+1}. #{movie.title}"
  end
  information(movies)
end

#latest_netflixObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/movie_helper/cli.rb', line 58

def latest_netflix
  if MovieHelper::Movie.latest_netflix.empty?
    puts "Loading..."
    latest_netflix_films = MovieHelper::Scraper.latest_netflix
    MovieHelper::Movie.create_from_list(latest_netflix_films)
    puts ""
  end
  puts "Here are our latest Netflix films:"
  movies = MovieHelper::Movie.latest_netflix
  movies.each.with_index do |movie, i|
    puts "#{i+1}. #{movie.title}"
  end
  information(movies)
end

#list_optionsObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/movie_helper/cli.rb', line 15

def list_options
  puts "Let us help you find a movie!"
  puts ""
  puts "Please select an option below:"
  puts "1. Random"
  puts "2. Latest on Netflix"
  puts "3. Latest on Amazon"
  puts "4. Latest Elsewhere"
  puts "5. Exit"
  selector
end

#more_info(movie) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/movie_helper/cli.rb', line 121

def more_info(movie)
  puts "Would you like more information about this movie?"
  puts "Type Y to get more information, or list to go back to the main menu."
  input = gets.chomp
  if input.upcase == "Y"
    display(movie)
  elsif input.downcase == "list"
    list_options
  else
    more_info(movie)
  end
end

#randomObject



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/movie_helper/cli.rb', line 46

def random
  puts "One moment while we randomly select your movie..."
  movie_hash = MovieHelper::Scraper.random
  movie = MovieHelper::Movie.new(movie_hash)
  puts ""
  puts "Your random movie is:"
  puts ""
  puts movie.title
  puts ""
  more_info(movie)
end

#satisfaction_checkObject



144
145
146
147
148
149
150
151
152
153
# File 'lib/movie_helper/cli.rb', line 144

def satisfaction_check
  input = nil
  until input == "yes" ||input == "y"
    puts "Are you satisfied with your movie choice?"
    input = gets.chomp.downcase
    if input == "no" || input == "n"
      input = try_again
    end
  end
end

#selectorObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/movie_helper/cli.rb', line 27

def selector
  input = gets.chomp
  case input
  when "1"
    random
  when "2"
    latest_netflix
  when "3"
    latest_amazon
  when "4"
    latest_elsewhere
  when "5" || "exit" || "quit"
  else
    puts "Invalid request."
    puts ""
    list_options
  end
end

#try_againObject



155
156
157
158
159
160
161
162
163
164
165
# File 'lib/movie_helper/cli.rb', line 155

def try_again
  puts "Would you like to try again?"
  input = gets.chomp.downcase
  if input == "yes" || input == "y"
    list_options
  elsif input == "no" || input == "n"
    "yes"
  else
    try_again
  end
end