diff --git a/Gemfile.lock b/Gemfile.lock index 2b2ab2c..86c6c37 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -18,6 +18,7 @@ GEM i18n (0.6.0) multi_json (1.3.4) pg (0.13.2) + pg (0.13.2-x86-mingw32) rake (0.9.2.2) rspec (2.9.0) rspec-core (~> 2.9.0) @@ -31,6 +32,7 @@ GEM PLATFORMS ruby + x86-mingw32 DEPENDENCIES activerecord diff --git a/config/database.yml.sample b/config/database.yml.sample deleted file mode 100644 index 44360d7..0000000 --- a/config/database.yml.sample +++ /dev/null @@ -1,6 +0,0 @@ -host: 'localhost' -adapter: 'postgresql' -database: 'watchman' -username: XXXXXXX -encoding: 'utf8' -pool: 5 diff --git a/db/migrate/001_create_games.rb b/db/migrate/001_create_games.rb new file mode 100644 index 0000000..e220c51 --- /dev/null +++ b/db/migrate/001_create_games.rb @@ -0,0 +1,10 @@ +class CreateGames < ActiveRecord::Migration + def change + create_table :games do |t| + t.string :name + t.string :designer + t.integer :players_min + t.integer :players_max + end + end +end diff --git a/db/migrate/002_create_publishers.rb b/db/migrate/002_create_publishers.rb new file mode 100644 index 0000000..2800799 --- /dev/null +++ b/db/migrate/002_create_publishers.rb @@ -0,0 +1,13 @@ +class CreatePublishers < ActiveRecord::Migration + def change + create_table :publishers do |t| + t.string :name + t.timestamps + end + + change_table :games do |t| + t.references :publisher + t.timestamps + end + end +end diff --git a/db/migrate/201205031230_create_shows.rb b/db/migrate/201205031230_create_shows.rb deleted file mode 100644 index 8197b57..0000000 --- a/db/migrate/201205031230_create_shows.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateShows < ActiveRecord::Migration - def change - create_table :shows do |t| - t.string :name - t.string :day_of_week - t.integer :hour_of_day - end - end -end diff --git a/db/migrate/201205031300_create_networks.rb b/db/migrate/201205031300_create_networks.rb deleted file mode 100644 index 2ef327c..0000000 --- a/db/migrate/201205031300_create_networks.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateNetworks < ActiveRecord::Migration - def change - create_table :networks do |t| - t.string :name - t.timestamps - end - - change_table :shows do |t| - t.references :network - t.timestamps - end - end -end diff --git a/db/seed.rb b/db/seed.rb index 3c028ff..b537771 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1,7 +1,12 @@ # Cleaning Out -Network.delete_all -Show.delete_all -amc = Network.create(name: "AMC") -nbc = Network.create(name: "NBC") -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) +Publisher.delete_all +Game.delete_all +ffg = Publisher.create(name: "Fantasy Flight Games") +slg = Publisher.create(name: "Sirlin Games") +zmg = Publisher.create(name: "Z-Man Games") + +Game.create(name: "Mansions of Madness", players_min: 2, players_max: 5, designer: "Corey Konieczka", publisher: ffg) +Game.create(name: "Android: Infiltration", players_min: 2, players_max: 6, designer: "Donald X. Vaccarino", publisher: ffg) +Game.create(name: "Puzzle Strike", players_min: 2, players_max: 4, designer: "David Sirlin", publisher: slg) +Game.create(name: "Flash Duel", players_min: 1, players_max: 5, designer: "David Sirlin", publisher: slg) +Game.create(name: "Pandemic", players_min: 2, players_max: 4, designer: "Matt Leacock", publisher: zmg) \ No newline at end of file diff --git a/models/game.rb b/models/game.rb new file mode 100644 index 0000000..200c8ee --- /dev/null +++ b/models/game.rb @@ -0,0 +1,9 @@ +class Game < ActiveRecord::Base + belongs_to :publisher + + validates_presence_of :name + + def to_s + "#{designer}'s \"#{name}\" for #{players_min}-#{players_max} players published by #{publisher}." # is for #{hour_of_day}:#{day_of_week}:00 on #{network} " + end +end diff --git a/models/network.rb b/models/network.rb deleted file mode 100644 index 00b697c..0000000 --- a/models/network.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Network < ActiveRecord::Base - has_many :shows - - def to_s - name - end -end diff --git a/models/publisher.rb b/models/publisher.rb new file mode 100644 index 0000000..12683bd --- /dev/null +++ b/models/publisher.rb @@ -0,0 +1,7 @@ +class Publisher < ActiveRecord::Base + has_many :games + + def to_s + name + end +end diff --git a/models/show.rb b/models/show.rb deleted file mode 100644 index 6c82f65..0000000 --- a/models/show.rb +++ /dev/null @@ -1,9 +0,0 @@ -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} " - end -end diff --git a/watchman.rb b/watchman.rb index ebe9be4..4c2b16f 100644 --- a/watchman.rb +++ b/watchman.rb @@ -5,11 +5,14 @@ Dir.glob('./models/*').each { |r| require r} 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 +puts "There are #{Game.count} games in the database:" +Game.all.each do |game| + puts game end + +puts "\nHow many players do you have? (Enter 1-6)" +player_count = gets.chomp().to_i +puts "\nGames for #{player_count} player(s):" +Game.all.each do |game| + puts game if game.players_min <= player_count && game.players_max >= player_count +end \ No newline at end of file