Class: Top100Movies::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



2
3
4
5
# File 'lib/top_100_movies/cli.rb', line 2

def call
  Top100Movies::Scraper.new.generate_movies
  start
end

#list_moviesObject



39
40
41
42
43
# File 'lib/top_100_movies/cli.rb', line 39

def list_movies
  Top100Movies::Movie.all.each do |movie|
    printf "%4s %-2s \n", "#{movie.rank}.", movie.name
  end
end

#startObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/top_100_movies/cli.rb', line 7

def start
  puts "******************************************************"
  puts "******        WELCOME TO TOP 100 MOVIES!        ******"
  puts "******************************************************"
  list_movies
  puts ""
  puts ""
  puts "Type 'exit' to exit the program"
  puts "Please enter the number of the movie you'd like to know more about"
  puts ""
  input = gets.chomp
  if input.to_i > 0 && input.to_i <= 100 #between
    movie = Top100Movies::Movie.find(input.to_i)
    Top100Movies::Movie.print_movie(movie)
    puts ""
    print "Would you like to checkout another movie? (y/n): "
    repeat = gets.chomp
    if repeat.downcase == 'y'
      start
    else
      puts "Goodbye!"
      exit
    end
  elsif input == "exit"
    puts "Goodbye!!"
    exit
  else
    puts "Wrong input"
    start
  end
end