From 8f42007c33cdf6da2d53f2da6d1e800bfe6ed1ec Mon Sep 17 00:00:00 2001 From: Patil Varvarian Date: Thu, 31 Oct 2013 14:16:21 -0700 Subject: [PATCH 1/6] just panda --- config/database.yml.sample | 6 ------ db/migrate/201205031230_create_shows.rb | 4 ++-- db/migrate/201205031300_create_networks.rb | 13 ------------- db/seed.rb | 18 ++++++++++++++++-- db/setup.rb | 12 +++++++----- models/network.rb | 3 ++- models/show.rb | 13 +++++++------ spec/.gitkeep | 0 watchman.rb | 18 ++++++++++++++++-- 9 files changed, 50 insertions(+), 37 deletions(-) delete mode 100644 config/database.yml.sample delete mode 100644 db/migrate/201205031300_create_networks.rb delete mode 100644 spec/.gitkeep 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/201205031230_create_shows.rb b/db/migrate/201205031230_create_shows.rb index 8197b57..1f2c3a5 100644 --- a/db/migrate/201205031230_create_shows.rb +++ b/db/migrate/201205031230_create_shows.rb @@ -2,8 +2,8 @@ class CreateShows < ActiveRecord::Migration def change create_table :shows do |t| t.string :name - t.string :day_of_week + t.string :day_of_week t.integer :hour_of_day end end -end +end \ No newline at end of file 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..3a96722 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1,7 +1,21 @@ -# Cleaning Out + Network.delete_all Show.delete_all amc = Network.create(name: "AMC") nbc = Network.create(name: "NBC") +netflix = Network.create(name: "Netflix") +#ondemand = Day.create(name: "OnDemand") 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) + + + +# have to create a filter for day. + +# day_of_week + +# list all days. +# + diff --git a/db/setup.rb b/db/setup.rb index 0e80690..7e87233 100644 --- a/db/setup.rb +++ b/db/setup.rb @@ -2,14 +2,16 @@ require 'active_record' require 'yaml' + connection_details = YAML::load(File.open('config/database.yml')) -# 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.create_database(connection_details.fetch('database')) rescue nil + +# Setup out connection_details +ActiveRecord::Base.establish_connection(connection_details.merge({database: 'postgres', schema_search_path: 'public'})) +# create the 'tv' database +ActiveRecord::Base.connection.create_database(connection_details.fetch(:database)) rescue nil # connect to it ActiveRecord::Base.establish_connection(connection_details) # Migrate all the things ActiveRecord::Migrator.migrate("db/migrate/") + \ No newline at end of file diff --git a/models/network.rb b/models/network.rb index 00b697c..5f97735 100644 --- a/models/network.rb +++ b/models/network.rb @@ -3,5 +3,6 @@ class Network < ActiveRecord::Base def to_s name - end + end end + diff --git a/models/show.rb b/models/show.rb index 6c82f65..f6f2fd3 100644 --- a/models/show.rb +++ b/models/show.rb @@ -1,9 +1,10 @@ -class Show < ActiveRecord::Base - belongs_to :network + class Show < ActiveRecord::Base + belongs_to :network - validates_presence_of :name + #validates_presence_of :name + def to_s + "#{name}, #{day_of_week}, #{hour_of_day}, #{network}" + end - def to_s - "#{name} airs at #{hour_of_day}:#{day_of_week}:00 on #{network} " - end end + \ No newline at end of file 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..f5301e3 100644 --- a/watchman.rb +++ b/watchman.rb @@ -7,9 +7,23 @@ puts "There are #{Show.count} in the database" +#puts "Pick a day" +#day = gets.chomp + 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 + +#Day.all.each do |day| + #puts "Shows airing on #{day}" + #day.shows.each do |show| + #puts show + # end +#end + + +# day.shows +# creat a table of just shows. From 3be1255f0179eb1036141e4543eef7e05d6e5421 Mon Sep 17 00:00:00 2001 From: Patil Varvarian Date: Thu, 31 Oct 2013 15:56:17 -0700 Subject: [PATCH 2/6] Panda & Tiger --- db/migrate/201205031230_create_shows.rb | 2 +- db/seed.rb | 2 +- watchman.rb | 21 +++++++++++---------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/db/migrate/201205031230_create_shows.rb b/db/migrate/201205031230_create_shows.rb index 1f2c3a5..7f6367a 100644 --- a/db/migrate/201205031230_create_shows.rb +++ b/db/migrate/201205031230_create_shows.rb @@ -1,4 +1,4 @@ -class CreateShows < ActiveRecord::Migration + class CreateShows < ActiveRecord::Migration def change create_table :shows do |t| t.string :name diff --git a/db/seed.rb b/db/seed.rb index 3a96722..e048c16 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -6,7 +6,7 @@ netflix = Network.create(name: "Netflix") #ondemand = Day.create(name: "OnDemand") 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: 19, 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) diff --git a/watchman.rb b/watchman.rb index f5301e3..10297b0 100644 --- a/watchman.rb +++ b/watchman.rb @@ -16,14 +16,15 @@ puts show end end +puts "------------------------" +Show.all.each do |show| + puts show +end +puts "------------------------" -#Day.all.each do |day| - #puts "Shows airing on #{day}" - #day.shows.each do |show| - #puts show - # end -#end - - -# day.shows -# creat a table of just shows. +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 From 1d421d70e4635fd83dcf9e0a3bc55717ae60b91a Mon Sep 17 00:00:00 2001 From: Patil Varvarian Date: Thu, 31 Oct 2013 18:08:36 -0700 Subject: [PATCH 3/6] panda, tiger, eagle --- db/migrate/201205031230_create_shows.rb | 2 +- db/seed.rb | 10 ---------- watchman.rb | 13 +++++++++---- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/db/migrate/201205031230_create_shows.rb b/db/migrate/201205031230_create_shows.rb index 7f6367a..1f2c3a5 100644 --- a/db/migrate/201205031230_create_shows.rb +++ b/db/migrate/201205031230_create_shows.rb @@ -1,4 +1,4 @@ - class CreateShows < ActiveRecord::Migration +class CreateShows < ActiveRecord::Migration def change create_table :shows do |t| t.string :name diff --git a/db/seed.rb b/db/seed.rb index e048c16..d934e4e 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -4,18 +4,8 @@ amc = Network.create(name: "AMC") nbc = Network.create(name: "NBC") netflix = Network.create(name: "Netflix") -#ondemand = Day.create(name: "OnDemand") 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: 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) - - -# have to create a filter for day. - -# day_of_week - -# list all days. -# - diff --git a/watchman.rb b/watchman.rb index 10297b0..1f81763 100644 --- a/watchman.rb +++ b/watchman.rb @@ -4,11 +4,10 @@ require "./db/setup" Dir.glob('./models/*').each { |r| require r} require "./db/seed" +require "./db/seeds" -puts "There are #{Show.count} in the database" -#puts "Pick a day" -#day = gets.chomp +puts "There are #{Show.count} in the database" Network.all.each do |network| puts "Shows airing on #{network}" @@ -21,10 +20,16 @@ puts show 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 + +puts "-------------------------" + + +Food.all.each do |food| + puts food +end From 2550e0b4323b2e0c5ae7e7bfc586108e1ad536c2 Mon Sep 17 00:00:00 2001 From: Patil Varvarian Date: Tue, 5 Nov 2013 18:17:57 -0800 Subject: [PATCH 4/6] Panda, Tiger Eagle --- db/migrate/201205031230_create_shows.rb | 4 ++-- db/seed.rb | 9 +++++++++ db/setup.rb | 12 +++++------- models/network.rb | 3 +-- models/show.rb | 13 ++++++------- watchman.rb | 17 +++++++++-------- 6 files changed, 32 insertions(+), 26 deletions(-) diff --git a/db/migrate/201205031230_create_shows.rb b/db/migrate/201205031230_create_shows.rb index 1f2c3a5..8197b57 100644 --- a/db/migrate/201205031230_create_shows.rb +++ b/db/migrate/201205031230_create_shows.rb @@ -2,8 +2,8 @@ class CreateShows < ActiveRecord::Migration def change create_table :shows do |t| t.string :name - t.string :day_of_week + t.string :day_of_week t.integer :hour_of_day end end -end \ No newline at end of file +end diff --git a/db/seed.rb b/db/seed.rb index d934e4e..df17e05 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1,6 +1,8 @@ Network.delete_all Show.delete_all +Coffee.delete_all + amc = Network.create(name: "AMC") nbc = Network.create(name: "NBC") netflix = Network.create(name: "Netflix") @@ -9,3 +11,10 @@ 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/db/setup.rb b/db/setup.rb index 7e87233..0e80690 100644 --- a/db/setup.rb +++ b/db/setup.rb @@ -2,16 +2,14 @@ require 'active_record' require 'yaml' - connection_details = YAML::load(File.open('config/database.yml')) - -# Setup out connection_details -ActiveRecord::Base.establish_connection(connection_details.merge({database: 'postgres', schema_search_path: 'public'})) -# create the 'tv' database -ActiveRecord::Base.connection.create_database(connection_details.fetch(:database)) rescue nil +# 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.create_database(connection_details.fetch('database')) rescue nil # connect to it ActiveRecord::Base.establish_connection(connection_details) # Migrate all the things ActiveRecord::Migrator.migrate("db/migrate/") - \ No newline at end of file diff --git a/models/network.rb b/models/network.rb index 5f97735..00b697c 100644 --- a/models/network.rb +++ b/models/network.rb @@ -3,6 +3,5 @@ class Network < ActiveRecord::Base def to_s name - end + end end - diff --git a/models/show.rb b/models/show.rb index f6f2fd3..6c82f65 100644 --- a/models/show.rb +++ b/models/show.rb @@ -1,10 +1,9 @@ - class Show < ActiveRecord::Base - belongs_to :network +class Show < ActiveRecord::Base + belongs_to :network - #validates_presence_of :name - def to_s - "#{name}, #{day_of_week}, #{hour_of_day}, #{network}" - end + validates_presence_of :name + def to_s + "#{name} airs at #{hour_of_day}:#{day_of_week}:00 on #{network} " + end end - \ No newline at end of file diff --git a/watchman.rb b/watchman.rb index 1f81763..897579b 100644 --- a/watchman.rb +++ b/watchman.rb @@ -4,8 +4,6 @@ require "./db/setup" Dir.glob('./models/*').each { |r| require r} require "./db/seed" -require "./db/seeds" - puts "There are #{Show.count} in the database" @@ -16,20 +14,23 @@ end end puts "------------------------" -Show.all.each do |show| - puts show -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 puts "-------------------------" +Coffee.all.each do |coffee| + puts coffee.name +end -Food.all.each do |food| - puts food +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 From e3e81c7e4a8ace2b556dfb97ee050618686a028d Mon Sep 17 00:00:00 2001 From: Patil Varvarian Date: Tue, 5 Nov 2013 18:38:00 -0800 Subject: [PATCH 5/6] Panda, Tiger, Eagel --- models/show.rb | 5 +++-- watchman.rb | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) 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/watchman.rb b/watchman.rb index 897579b..1131456 100644 --- a/watchman.rb +++ b/watchman.rb @@ -19,8 +19,13 @@ day = gets.chomp().capitalize puts "Shows airing on #{day}" -Show.all.each do |show| - puts show if show.day_of_week == 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 "-------------------------" @@ -31,6 +36,11 @@ 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 +#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 From 83801afd2502a78cc8ce9a2d77f5d7cc885c349d Mon Sep 17 00:00:00 2001 From: var114 Date: Tue, 5 Nov 2013 18:45:02 -0800 Subject: [PATCH 6/6] Delete README.md --- README.md | 50 -------------------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 README.md 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)