Skip to content

Instantly share code, notes, and snippets.

@damianesteban
Created April 5, 2014 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damianesteban/9995696 to your computer and use it in GitHub Desktop.
Save damianesteban/9995696 to your computer and use it in GitHub Desktop.
v 0.01 of a Movie Database Application written in Ruby.
# First, make a Hash with a title of a movie, give it a rating.
movies = Hash.new
puts "What would you like to do?"
choice = gets.chomp
case choice
when "add"
puts "What is the title of the movie you would like to add?"
title = gets.chomp.to_sym
puts "What rating would you like to assign to #{title}?"
rating = gets.chomp
if movies[title.to_sym].nil?
movies[title.to_sym] = rating
else
puts "Your movie is already in the database."
end
when "update"
puts "What is the title of the movie you would like to add?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "Your movie is not in the hash. How can you update it?"
else
puts "What rating would you like to assign to the movie?"
movies[title.to_sym] = rating
end
when "display"
movies.each { |movie, rating| puts "#{movie}: #{rating}" }
when "delete"
puts "Which movie would you like to delete?"
title = gets.chomp
if movies[title.to_sym].nil?
movies.delete(title)
else
puts "That movie is not in the database."
end
else
puts "Error!"
end
# Notes:
# This is a basic project that I adapted from codeacademy. As it stands
# right now it has limited functionality (as you can see)
# My goals for the project are as follows:
#
# TODO:
# 1.) write a class / class methods
# 2.) enable the user to loop back to the initial prompt, and exit when they
# want to.
# 3.) use mongodb for the database, or maybe postgres I suppose. I'd like to
# learn some more about mongo. I know I asked you once if you have used
# mongo before, I don't remember what you said.
# 4.) Eventually make this a Rails-based web application.
#
# A project like this would be a good opportunity to learn git-flow
# and implement feature branches. Let me know what you think.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment