Skip to content

Done assignment, advanced level #31

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions db/migrate/201402271820_create_games.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateGames < ActiveRecord::Migration
def change
create_table :games do |t|
t.string :name
t.string :genre
t.string :teaser
end
end
end
9 changes: 9 additions & 0 deletions db/seed.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# Cleaning Out
Network.delete_all
Show.delete_all
Game.delete_all
amc = Network.create(name: "AMC")
nbc = Network.create(name: "NBC")
m1 = Network.create(name: "M1")
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: "Incantesimo", day_of_week: "Friday", hour_of_day: 17, network: m1)
Show.create(name: "The next one", day_of_week: "Monday", hour_of_day: 18, network: m1)
Game.create(name: "Dungeon Keeper", genre: "Strategy", teaser: "It's good to be evil.")
Game.create(name: "Tyrian 2000", genre: "Shoot \'em up", teaser: "The best shoot \'em up game of all the time!")
Game.create(name: "Warcraft", genre: "Strategy", teaser: "Warcraft is a franchise of video games, novels, and other media originally created by Blizzard Entertainment.")
Game.create(name: "Diablo", genre: "RPG", teaser: "Diablo is an action role-playing hack and slash video game developed by Blizzard North and released by Blizzard Entertainment on December 31, 1996.")
Game.create(name: "MDK", genre: "TPS", teaser: "MDK is a 1997 third-person shooter video game developed by Shiny Entertainment. It was one of the first PC games to require a Pentium or equivalent processor, and did not initially have a GPU requirement.")
6 changes: 6 additions & 0 deletions models/game.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Game < ActiveRecord::Base
validates_presence_of :name, :genre, :teaser
def to_s
"Name: #{name}\ngenre: #{genre}\nteaser: #{teaser}\n"
end
end
52 changes: 47 additions & 5 deletions watchman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,53 @@
Dir.glob('./models/*').each { |r| require r}
require "./db/seed"

puts "There are #{Show.count} in the database"
puts "Would you like to check TV shows or games?"

Network.all.each do |network|
decision = gets.chomp

case decision
when "TV shows" || "shows"

puts "There are #{Show.count} shows in the database"

puts "When would you like to watch your show?"

day_to_watch = gets.chomp

Network.joins(:shows).where("shows.day_of_week" => day_to_watch).each do |network|
puts "Shows airing on #{network}"
network.shows.each do |show|
puts show
end
network.shows.each do |show|
Copy link
Member

Choose a reason for hiding this comment

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

If you're going to do something inside of a loop, I prefer to limit the results, and then act on them.

In this case, you just want the Shows, right? So, why not query for the shows, instead of the network? How might that look?

unless show.day_of_week != day_to_watch
puts show #show.to_s
end
end
end

when "games"

puts "There are #{Game.count} games in the database"

puts "You can choose one of the following games:"

Game.all.each do |game|
puts game.to_s
end

puts "Which game would you like to know more about?"

game_selected = gets.chomp

game_result = Game.where("name" => game_selected)

unless game_result.blank?

game_result.each do |game|
puts game.to_s
end

else
puts "sorry Dave, I can't do that right now"
end
else
puts "sorry Dave, I can't do that right now"
end