diff --git a/README.md b/README.md deleted file mode 100644 index fce7a09..0000000 --- a/README.md +++ /dev/null @@ -1,50 +0,0 @@ -Episode3: Watchman -- Datastores in YML and Postgres -==================================================== - -Storing data in Postgres, with migrations, outside of Rails - -Your Assignment ---------------- - -1. Download and install PostgreSQL (see show notes) -2. Clone, fork this repo and copy the config/database.yml.sample to config/database.yml, edit with values - -Panda Level ------------ - -1. Add 2 more TV shows to the seeds file -2. When I run `ruby watchman.rb`, Have it output all TV shows - -Tiger Level ------------ - -1. Ask the user what day they want to watch shows? -2. Output only the shows matching that day of the week - -Eagle (Advanced) Level ----------------------- - -4. Create a table (using the migrations) which represents a hobby of yours: Fishing, Sports, Cooking, etc. -3. When I run ruby watchman.rb - * Fill the table with 5 records (Recipe.create) - * Have it show me all the records, with a nicely implemented to_s method - * Ask me (the user) what I want to show. Example, if you have Recipe with :name and :ingredients: - -``` -[Recipes.all] -"Cornbread Muffins", [corn, butter, oil] -"Tacos", [tortilla, avacado, shrimp] - -What would you like to learn more about? - -#[editor: if I enter "Tacos" I'll see the Tacos recipe. If I enter nutella, I see "sorry Dave, I can't do that right now"] -``` - -Show Notes ------------ - -* [Postgres for Mac Installer](http://postgresapp.com/) -* [Postgres for Windows Installer](http://www.postgresql.org/download/windows/) -* Mac types can also: `brew install postgres` but the oneclick is very nice. - -Copyright: Jesse Wolgamott, MIT License (See LICENSE) 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/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..df17e05 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1,7 +1,20 @@ -# Cleaning Out + Network.delete_all Show.delete_all +Coffee.delete_all + amc = Network.create(name: "AMC") nbc = Network.create(name: "NBC") +netflix = Network.create(name: "Netflix") 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: "Community", day_of_week: "Thursday", hour_of_day: 19, network: nbc) +Show.create(name: "House of Cards", day_of_week: "Thursday", hour_of_day: 0, network: netflix) +Show.create(name: "Orange is the New Black", day_of_week: "Sunday" , hour_of_day: 0, network: netflix) + +Coffee.create(name: 'Costa Rica', grade: 'SHB EP', process: 'Washed', region: 'Santa Maria de Dota', roast: 'Full City') +Coffee.create(name: 'Guatemala', grade: 'SHB', process: 'Washed', region: 'San Pedro Necta', roast: 'City') +Coffee.create(name: 'Honduras', grade: 'SHB', process: 'Washed', region: 'Ocotopeque', roast: 'City - Full City') +Coffee.create(name: 'Bolivia', grade: 'n/a', process: 'n/a', region: 'Caranavi', roast: 'Just brew') +Coffee.create(name: 'Java', grade: 'One', process: 'Washed', region: 'Java Sunda', roast: 'Full City') + + diff --git a/models/show.rb b/models/show.rb index 6c82f65..557332b 100644 --- a/models/show.rb +++ b/models/show.rb @@ -1,9 +1,10 @@ class Show < ActiveRecord::Base belongs_to :network - - validates_presence_of :name + validates_presence_of :name def to_s "#{name} airs at #{hour_of_day}:#{day_of_week}:00 on #{network} " end end + + diff --git a/spec/.gitkeep b/spec/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/watchman.rb b/watchman.rb index ebe9be4..1131456 100644 --- a/watchman.rb +++ b/watchman.rb @@ -9,7 +9,38 @@ Network.all.each do |network| puts "Shows airing on #{network}" - network.shows.each do |show| + network.shows.each do |show| #this is really cool puts show - end + end +end +puts "------------------------" + +puts "Which day do you want to watch the show?" +day = gets.chomp().capitalize +puts "Shows airing on #{day}" + + +#Show.all.each do |show| +# puts show if show.day_of_week == day +#end + +Show.all.to_a.select{|show| show.day_of_week == day}.each do |show| + puts show +end + +puts "-------------------------" + +Coffee.all.each do |coffee| + puts coffee.name +end + +puts "Which coffee do you want to know more about?" +cof = gets.chomp().capitalize +#Coffee.all.each do |coffee| + # puts coffee if coffee.name == cof +#end + +Coffee.all.to_a.select{|coffee| coffee == cof}.each do |coffee| + puts coffee + end