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/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 3c028ff..e74a7d9 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1,7 +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) +# 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/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/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 6c82f65..57ebaba 100644 --- a/models/show.rb +++ b/models/show.rb @@ -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 #{hour_of_day}:00, #{day_of_week} on #{network} " end end diff --git a/watchman.rb b/watchman.rb index ebe9be4..28ac943 100644 --- a/watchman.rb +++ b/watchman.rb @@ -1,15 +1,82 @@ require 'rubygems' require 'bundler/setup' +require 'io/console' -require "./db/setup" -Dir.glob('./models/*').each { |r| require r} -require "./db/seed" +require './db/setup' +Dir.glob('./models/*').each { |r| require r } +require './db/seed' -puts "There are #{Show.count} in the database" +## +# Begin the program by asking the user what they would like to do. +## +def start + puts <<-EOF +What would you like to do today? -Network.all.each do |network| - puts "Shows airing on #{network}" - network.shows.each do |show| - puts show - end + (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 + + +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