From f64950515c2737477ac4cae9ed4ea335209a62a8 Mon Sep 17 00:00:00 2001 From: PDaily Date: Thu, 1 May 2014 01:10:53 +0000 Subject: [PATCH 1/2] Tiger level. Added 2 shows, and request a day to search from user. --- config/database.yml.sample | 2 +- db/seed.rb | 4 ++++ db/setup.rb | 2 +- models/show.rb | 4 ++-- watchman.rb | 21 +++++++++++++-------- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/config/database.yml.sample b/config/database.yml.sample index 44360d7..030cce6 100644 --- a/config/database.yml.sample +++ b/config/database.yml.sample @@ -3,4 +3,4 @@ adapter: 'postgresql' database: 'watchman' username: XXXXXXX encoding: 'utf8' -pool: 5 +pool: 5 \ No newline at end of file diff --git a/db/seed.rb b/db/seed.rb index 3c028ff..44b95e3 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -3,5 +3,9 @@ Show.delete_all amc = Network.create(name: "AMC") nbc = Network.create(name: "NBC") +fx = Network.create(name: "FX") +bbca = Network.create(name: "BBC America") 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: "Archer", day_of_week: "Monday", hour_of_day: 19 , network: fx) +Show.create(name: "Dr. Who", day_of_week: "Wednesday", hour_of_day: 20, network: bbca) \ No newline at end of file diff --git a/db/setup.rb b/db/setup.rb index 0e80690..73df786 100644 --- a/db/setup.rb +++ b/db/setup.rb @@ -7,7 +7,7 @@ # Setup out connection details ActiveRecord::Base.establish_connection(connection_details.merge({'database'=> 'postgres', 'schema_search_path'=> 'public'})) # create the 'tv' database -ActiveRecord::Base.connection.drop_database (connection_details.fetch('database')) rescue nil +ActiveRecord::Base.connection.drop_database(connection_details.fetch('database')) rescue nil ActiveRecord::Base.connection.create_database(connection_details.fetch('database')) rescue nil # connect to it ActiveRecord::Base.establish_connection(connection_details) diff --git a/models/show.rb b/models/show.rb index 6c82f65..eaf8b2f 100644 --- a/models/show.rb +++ b/models/show.rb @@ -1,9 +1,9 @@ -class Show < ActiveRecord::Base + class Show < ActiveRecord::Base belongs_to :network validates_presence_of :name def to_s - "#{name} airs at #{hour_of_day}:#{day_of_week}:00 on #{network} " + "#{name} airs at #{hour_of_day}:00, #{day_of_week} on #{network} " end end diff --git a/watchman.rb b/watchman.rb index ebe9be4..02746c1 100644 --- a/watchman.rb +++ b/watchman.rb @@ -1,15 +1,20 @@ require 'rubygems' require 'bundler/setup' -require "./db/setup" +require './db/setup' Dir.glob('./models/*').each { |r| require r} -require "./db/seed" +require './db/seed' puts "There are #{Show.count} in the database" -Network.all.each do |network| - puts "Shows airing on #{network}" - network.shows.each do |show| - puts show - end -end +puts 'What day would you like to search?' +day = gets.strip.capitalize +results = Show.where(day_of_week: day) +if results == [] + puts "There are no shows on #{day}" +else + puts "These are the shows that are playing on #{day}" + results.each do |show| + puts show + end +end \ No newline at end of file From 6892d9ec5495c81669423fda9d5d998463f1b64c Mon Sep 17 00:00:00 2001 From: PDaily Date: Mon, 12 May 2014 00:36:40 +0000 Subject: [PATCH 2/2] Finished whole assignment to Eagle. --- db/migrate/201404302116_create_games.rb | 10 +++ db/seed.rb | 32 ++++++++- models/game.rb | 8 +++ models/show.rb | 2 +- watchman.rb | 88 +++++++++++++++++++++---- 5 files changed, 125 insertions(+), 15 deletions(-) create mode 100644 db/migrate/201404302116_create_games.rb create mode 100644 models/game.rb diff --git a/db/migrate/201404302116_create_games.rb b/db/migrate/201404302116_create_games.rb new file mode 100644 index 0000000..0d0fe88 --- /dev/null +++ b/db/migrate/201404302116_create_games.rb @@ -0,0 +1,10 @@ +class CreateGames < ActiveRecord::Migration + def change + create_table :games do |t| + t.string :name + t.string :system + t.string :esrb_rating + t.string :studio + end + end +end diff --git a/db/seed.rb b/db/seed.rb index 44b95e3..e74a7d9 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1,11 +1,41 @@ # Cleaning Out +Game.delete_all Network.delete_all Show.delete_all +# Declare Networks amc = Network.create(name: "AMC") nbc = Network.create(name: "NBC") fx = Network.create(name: "FX") bbca = Network.create(name: "BBC America") +# Add in shows 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: "Archer", day_of_week: "Monday", hour_of_day: 19 , network: fx) -Show.create(name: "Dr. Who", day_of_week: "Wednesday", hour_of_day: 20, network: bbca) \ No newline at end of file +Show.create(name: "Dr. Who", day_of_week: "Wednesday", hour_of_day: 20, network: bbca) +# Add in games +# +# Xbox360 +Game.create(name: "Halo: Combat Evolved", system: "Xbox360", esrb_rating: "M", studio: "Bungie") +Game.create(name: "Dark Souls", system: "Xbox360", esrb_rating: "M", studio: "From Software") +Game.create(name: "Crysis", system: "Xbox360", esrb_rating: "M", studio: "Crytek Frankfurt") +Game.create(name: "Dragon Age: Origins", system: "Xbox360", esrb_rating: "M", studio: "Bioware") +# XboxOne +Game.create(name: "TitanFall", system: "XboxOne", esrb_rating: "M", studio: "Respawn Entertainment") +Game.create(name: "Ryse: Son of Rome", system: "XboxOne", esrb_rating: "M", studio: "Crytek") +Game.create(name: "Dead Rising 3", system: "XboxOne", esrb_rating: "M", studio: "Capcom") +Game.create(name: "Crimson Dragon", system: "XboxOne", esrb_rating: "M", studio: "Grounding Inc.") +# PS3 +Game.create(name: "The Last of Us", system: "PS3", esrb_rating: "M", studio: "Naughty Dog") +Game.create(name: "Assassins Creed IV: Black Flag", system: "PS3", esrb_rating: "M", studio: "Ubisoft") +Game.create(name: "Grand Theft Auto V", system: "PS3", esrb_rating: "M", studio: "Rockstar") +Game.create(name: "Metal Gear Solid 4", system: "PS3", esrb_rating: "M", studio: "Konami") +# PS4 +Game.create(name: "Contrast", system: "PS4", esrb_rating: "M", studio: "Compulsion Games") +Game.create(name: "DiveKick", system: "PS4", esrb_rating: "M", studio: "One True Game Studios") +Game.create(name: "Super Motherland", system: "PS4", esrb_rating: "M", studio: "XGen Studios") +Game.create(name: "Warframe", system: "PS4", esrb_rating: "M", studio: "Digital Extremes") +# GameBoy +Game.create(name: "Fire Emblem: Awakening", system: "GameBoy", esrb_rating: "M", studio: "Nintendo") +Game.create(name: "The Legend of Zelda: A Link Between Worlds", system: "GameBoy", esrb_rating: "M", studio: "Nintendo") +Game.create(name: "Mario Kart 7", system: "GameBoy", esrb_rating: "M", studio: "Nintendo") +Game.create(name: "Super Mario 3D Land", system: "GameBoy", esrb_rating: "M", studio: "Nintendo") \ No newline at end of file diff --git a/models/game.rb b/models/game.rb new file mode 100644 index 0000000..50f5d4c --- /dev/null +++ b/models/game.rb @@ -0,0 +1,8 @@ +class Game < ActiveRecord::Base + + validates_presence_of :name, :system, :esrb_rating, :studio + + def to_s + "#{name} - Developed by #{studio}. Rated: #{esrb_rating}" + end +end diff --git a/models/show.rb b/models/show.rb index eaf8b2f..57ebaba 100644 --- a/models/show.rb +++ b/models/show.rb @@ -1,4 +1,4 @@ - class Show < ActiveRecord::Base +class Show < ActiveRecord::Base belongs_to :network validates_presence_of :name diff --git a/watchman.rb b/watchman.rb index 02746c1..28ac943 100644 --- a/watchman.rb +++ b/watchman.rb @@ -1,20 +1,82 @@ require 'rubygems' require 'bundler/setup' +require 'io/console' require './db/setup' -Dir.glob('./models/*').each { |r| require r} +Dir.glob('./models/*').each { |r| require r } require './db/seed' -puts "There are #{Show.count} in the database" - -puts 'What day would you like to search?' -day = gets.strip.capitalize -results = Show.where(day_of_week: day) -if results == [] - puts "There are no shows on #{day}" -else - puts "These are the shows that are playing on #{day}" - results.each do |show| - puts show +## +# Begin the program by asking the user what they would like to do. +## +def start + puts <<-EOF +What would you like to do today? + + (1)I'd like to see what shows are playing. + + (2)I'd like to see what games I have. + +EOF + sel = STDIN.getch.to_i + case sel + when 1 + show_search + when 2 + game_search + end +end + + +def show_search + days_of_week = %w[Monday Tuesday Wednesday Thursday Friday Saturday Sunday] + + puts "There are #{Show.count} shows in the database\n\n" + + puts 'What day would you like to search?' + day_selection = gets.strip.capitalize + ## For the glory of eye candy + puts "Searching...\n\n" + sleep 1 + if day_selection + results = Show.where(day_of_week: day_selection) + if results == [] + puts "There are no shows on #{day_selection}" + else + puts "These are the shows that are playing on #{day_selection}" + results.each do |show| + puts show + end + end end -end \ No newline at end of file +end + + +def game_search + game_systems = %w[Xbox360 XboxOne PS3 PS4 GameBoy] + + puts "There are #{Game.count} games in the database.\n\n" + + puts "What system do you want to search on?\n\n" + ## Pull each system out of game_systems and label them by number. + game_systems.each do |system| + puts " (#{game_systems.index(system)+1}) #{system}" + end + user_selection = STDIN.getch.to_i-1 + puts "Searching...\n\n" + sleep 1 + system_selection = game_systems[user_selection] + if system_selection + results = Game.where(system: system_selection) + if results == [] + puts "There are no games listed for that system." + else + puts "These are the games you have for #{system_selection}:\n\n" + results.each do |game| + puts game + end + end + end +end + +start \ No newline at end of file