Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panda and Tiger Submission #29

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions db/migrate/201401161200_create_reviews.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateReviews < ActiveRecord::Migration
def change
create_table :reviews do |t|
t.string :movie
t.integer :rating
t.string :reviewer
t.string :synopsis
end
end
end
29 changes: 27 additions & 2 deletions db/seed.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
# Cleaning Out
Network.delete_all
Show.delete_all
amc = Network.create(name: "AMC")
nbc = Network.create(name: "NBC")
Review.delete_all
amc = Network.create(name: "AMC")
nbc = Network.create(name: "NBC")
bravo = Network.create(name: "Bravo")
Show.create(name: "Mad Men", day_of_week: "Sunday", hour_of_day: 22, network: amc)
Show.create(name: "Community", day_of_week: "Thursday", hour_of_day: 20, network: nbc)
Show.create(name: "Top Chef", day_of_week: "Wednesday", hour_of_day: 19, network: bravo)
Show.create(name: "Walking Dead", day_of_week: "Sunday", hour_of_day: 20, network: amc)

Review.create(movie: "Pulp Fiction",
rating: 5,
reviewer: "Anthony Lane",
synopsis: "The talk is dirty and funny, the violence always waiting just around the corner.")
Review.create(movie: "Raiders of the Lost Ark",
rating: 5,
reviewer: "Gene Siskel",
synopsis: "Yes, it's as entertaining as you have heard. Maybe more so. Raiders of the Lost Ark is, in fact, about as entertaining as a commercial movie can be.")
Review.create(movie: "Amadeus",
rating: 5,
reviewer: "Gene Siskel",
synopsis: "The subject of artistic creation is typically handled badly in the movies.... [Amadeus] treats the subject of creativity in a fresh way.")
Review.create(movie: "American Hustle",
rating: 5,
reviewer: "Joe Neumaier",
synopsis: "It turns out that comb-overs, cleavage, cocaine and kookiness are an unbeatable combo.")
Review.create(movie: "The Big Lebowski",
rating: 5,
reviewer: "Rick Groen",
synopsis: "A typical Coen brothers film is like no film you've ever seen.")
5 changes: 5 additions & 0 deletions models/review.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Review < ActiveRecord::Base
def to_s
"#{movie}, Reviewed by: #{reviewer}, Rating: #{rating}, Review: #{synopsis}"
end
end
2 changes: 1 addition & 1 deletion models/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ class Show < ActiveRecord::Base
validates_presence_of :name

def to_s
"#{name} airs at #{hour_of_day}:#{day_of_week}:00 on #{network} "
"#{name} airs at #{day_of_week}, #{hour_of_day}:00 on #{network}."
end
end
23 changes: 17 additions & 6 deletions watchman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@
Dir.glob('./models/*').each { |r| require r}
require "./db/seed"

puts "There are #{Show.count} in the database"
i=0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont think you need to keep this, right?


Network.all.each do |network|
puts "Shows airing on #{network}"
network.shows.each do |show|
puts show
end
puts "***********************"
puts "* Welcome to WATCHMAN *"
puts "***********************"
puts "There are #{Review.count} reviews in the database:"
puts ""
Review.all.each do |review|
i+=1
puts "#{review.movie}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should just do

puts review.movie

end
puts "What movie review would you like to see?"
print "> "

movie_selection = gets.chomp.downcase

my_selection = Review.all.select { |review| review.movie.downcase == movie_selection }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is database backed, we can use the DB to query now. So, you could do:

my_selection = Review.where(movie: movie_selection)

puts "Oops... we don't have a review for #{movie_selection} yet." if my_selection.empty?
my_selection.each { |review| puts review }