Class: NewMovies::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/new_movies/CLI.rb

Constant Summary collapse

WIDTH =
70

Instance Method Summary collapse

Instance Method Details

#callObject



18
19
20
21
# File 'lib/new_movies/CLI.rb', line 18

def call
  NewMovies::Scraper.scrape_coming_soon_movies
  main_menu
end

#center(string, c = "-") ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/new_movies/CLI.rb', line 5

def center(string, c = "-")
  string = " #{string} " if string != ""
  until string.length >= WIDTH
    string.prepend(c)
    string << (c)
  end
  string.prepend("\n")
end

#goodbyeObject



85
86
87
88
# File 'lib/new_movies/CLI.rb', line 85

def goodbye
  puts "See you next time!"
  exit
end

#list_new_moviesObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/new_movies/CLI.rb', line 23

def list_new_movies
  puts center("MOVIES COMING SOON TO CINEMARK THEATRES")
  puts " "
  NewMovies::Movie.all.each_with_index do |movie, index|
    puts "    #{index+1}. #{movie.title}" if index.to_i+1 < 10
    puts "   #{index+1}. #{movie.title}" if index.to_i+1 >= 10
  end
    puts center("END OF LIST")
    puts " "
end


50
51
52
53
54
# File 'lib/new_movies/CLI.rb', line 50

def main_menu
  list_new_movies
  puts "Which movie do you want more details about?"
  menu
end


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/new_movies/CLI.rb', line 34

def menu
  print "Please select a number: "
  input = gets.strip.downcase
  if input == "exit"
    goodbye
  elsif input.to_i > 0 && input.to_i <= NewMovies::Movie.all.length
    movie_details(input)
    menu_restart
  elsif input == "list"
    menu
  else
    puts "Invalid entry."
    menu
  end
end


56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/new_movies/CLI.rb', line 56

def menu_restart
  puts " "
  print "Enter 'list' to view the movies again or enter 'exit': "
    input = gets.strip.downcase
    if input == "exit"
      goodbye
    elsif input == "list"
      main_menu
    else
      menu_restart
    end
end

#movie_details(input) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/new_movies/CLI.rb', line 69

def movie_details(input)
  details = NewMovies::Movie.find_movie_by_index(input)
  puts center("#{details.title.upcase}")
  puts " "
  puts "  URL: #{details.url}" if details.url
  puts "  Runtime: #{details.runtime}" if details.runtime
  puts "  Rating: #{details.rating}" if details.rating != ""
  puts "  Genre: #{details.genre}" if details.genre
  puts "  Release Date: #{details.release_date}" if details.release_date
  puts "  Director: #{details.director}" if details.director
  puts wrap("  Cast: #{details.cast}") if details.cast
  puts wrap("\n  Synopsis: #{details.synopsis}") if details.synopsis
  puts "  Movie Site: #{details.movie_site}" if details.movie_site
  puts center("END OF DETAILS")
end

#wrap(s) ⇒ Object



14
15
16
# File 'lib/new_movies/CLI.rb', line 14

def wrap(s)
  s.gsub(/(.{1,#{WIDTH}})(\s+|\Z)/, "\\1\n  ")
end