Class: BestMovies::CLI

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

Constant Summary collapse

BASE_PATH =
"https://www.rottentomatoes.com"

Instance Method Summary collapse

Instance Method Details

#add_infoObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/best_movie_year/cli.rb', line 32

def add_info
  puts "Would you like more information? (Y/N)"
  input = gets.strip
  if input.downcase == "y"
    puts ""
    print_desc
    puts ""
    diff_year
  elsif input.downcase == "n"
    puts ""
    diff_year
  else
    puts ""
    puts "Invalid entry. Please enter Y or N"
    puts ""
    print_movies
  end
end

#callObject



5
6
7
8
# File 'lib/best_movie_year/cli.rb', line 5

def call
  puts "Welcome!"
  start
end

#diff_yearObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/best_movie_year/cli.rb', line 51

def diff_year
  puts "Would you like to enter a different year? (Y/N)"
  input = gets.strip
  if input.downcase == "n"
    puts ""
    puts "Goodbye."
  elsif input.downcase == "y"
    puts ""
    BestMovies::Movie.reset_all
    start
  else
    puts "Invalid entry. Please enter Y or N."
    puts ""
    diff_year
  end
end

#make_movies(input) ⇒ Object



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

def make_movies(input)
  movie_array = BestMovies::Movie.scrape_movies(BASE_PATH + "/top/bestofrt/?year=" + input)
  BestMovies::Movie.create(movie_array)
end


25
26
27
28
29
30
# File 'lib/best_movie_year/cli.rb', line 25

def print_desc
  BestMovies::Movie.all.first(10).each.with_index(1) { |movie, i|
    puts "#{i}. #{wrap(movie.title[:desc][:desc])}"
    puts ""
  }
end


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

def print_movies
  BestMovies::Movie.all.first(10).each.with_index(1) { |movie, i|
    puts "#{i}. #{movie.title[:title]}"
    url = "#{movie.title[:url]}"
    BestMovies::Movie.scrape_desc(url)
  }
  puts ""
  add_info
end

#startObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/best_movie_year/cli.rb', line 68

def start
  puts "Please enter a four-digit year from 1950 to 2018 to view the top 10 movies of that year. To exit, please type 'EXIT':"
  input = gets.strip
  if input.to_i >= 1950 && input.to_i <= 2018
    make_movies(input)
    puts ""
    puts "Top 10 Movies of #{input.to_i}"
    print_movies
  elsif input.downcase == "exit"
    puts ""
    puts "Goodbye."
  else
    puts ""
    puts "Invalid entry."
    puts ""
    start
  end
end

#wrap(s, width = 73) ⇒ Object



87
88
89
# File 'lib/best_movie_year/cli.rb', line 87

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