From f235e630dfefcd7eba0739c12dac40c386e610be Mon Sep 17 00:00:00 2001 From: Joanna Marquez Date: Sat, 23 Feb 2013 21:54:18 -0500 Subject: [PATCH] Completed Tiger Level for Episode2-Summer2012 --- movie_json.rb | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/movie_json.rb b/movie_json.rb index d8a91d7..38acce8 100644 --- a/movie_json.rb +++ b/movie_json.rb @@ -1,20 +1,38 @@ require_relative "lib/movie" require_relative "lib/api" -def find_movie - puts "OH HAI. Search?" - movie_title = gets - movie = Api.search_by_title(movie_title) - puts "Found: #{movie.title}. Score: #{movie.score}" +def find_movie(movies_hash) + puts "Add a movie you really like..." + movie_title = gets.chop + + begin + movies = Api.search_by_title(movie_title) + hash = {movies.title => movies.score} + movies_hash = hash.merge(movies_hash) + rescue StandardError=>e + puts e + puts "Error: Movie '#{movie_title}' not found!" + else + puts "Found: #{movies.title}. Score: #{movies.score}" + count = score = 0 + movies_hash.each {|key, value| + count = count + 1 + score = score + value + } + end + average = (score/count).to_f + puts "Your Average Taste in Movies: #{average}" + movies_hash end -find_movie +movies_hash = {} +movies_hash = find_movie(movies_hash) while true do puts "Search Again (Y/N)" answer = gets.upcase[0] if answer == "Y" - find_movie + movies_hash = find_movie(movies_hash) else break end