diff --git a/db/migrate/201402271820_create_games.rb b/db/migrate/201402271820_create_games.rb new file mode 100644 index 0000000..2227b9e --- /dev/null +++ b/db/migrate/201402271820_create_games.rb @@ -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 diff --git a/db/seed.rb b/db/seed.rb index 3c028ff..ba906a5 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -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.") diff --git a/models/game.rb b/models/game.rb new file mode 100644 index 0000000..06ec241 --- /dev/null +++ b/models/game.rb @@ -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 \ No newline at end of file diff --git a/watchman.rb b/watchman.rb index ebe9be4..c3c24e9 100644 --- a/watchman.rb +++ b/watchman.rb @@ -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| + 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