Skip to content
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
2 changes: 1 addition & 1 deletion config/database.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ adapter: 'postgresql'
database: 'watchman'
username: XXXXXXX
encoding: 'utf8'
pool: 5
pool: 5
10 changes: 10 additions & 0 deletions db/migrate/201404302116_create_games.rb
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions db/seed.rb
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 1 addition & 1 deletion db/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions models/game.rb
Original file line number Diff line number Diff line change
@@ -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
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 #{hour_of_day}:00, #{day_of_week} on #{network} "
end
end
85 changes: 76 additions & 9 deletions watchman.rb
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

Nice use of the multi-line string!

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
Copy link
Member

Choose a reason for hiding this comment

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

This is probably pretty hard to read in the future. eg: "why are we doing -1 here?" "Why +1 later"?

Recommend moving these bits of functionality to methods that have names that make sense to future-you

puts "Searching...\n\n"
sleep 1
system_selection = game_systems[user_selection]
if system_selection
Copy link
Member

Choose a reason for hiding this comment

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

These nested IF/s are also pretty hard to read. Guideline: if you need nested ifs, move the outer if into a method

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