From 15edf6ad42f53dea4ece06389f76d32909010ed0 Mon Sep 17 00:00:00 2001 From: noahpatterson Date: Tue, 31 Dec 2013 18:44:47 -0500 Subject: [PATCH 1/4] Panda level. Add 2 more shows. --- db/seed.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/db/seed.rb b/db/seed.rb index 3c028ff..6aeb372 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1,7 +1,11 @@ # Cleaning Out Network.delete_all Show.delete_all + amc = Network.create(name: "AMC") nbc = Network.create(name: "NBC") +showtime = Network.create(name: "Showtime") 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: "Hannibal", day_of_week: "Monday", hour_of_day: 20, network: nbc) +Show.create(name: "Homeland", day_of_week: "Thursday", hour_of_day: 20, network: showtime) \ No newline at end of file From 7876db6d66103f5652764330dce88aac4797f4f4 Mon Sep 17 00:00:00 2001 From: noahpatterson Date: Tue, 31 Dec 2013 20:15:45 -0500 Subject: [PATCH 2/4] Tiger level. return only searched days. add spec --- models/show.rb | 2 ++ spec/show_spec.rb | 13 +++++++++++++ watchman.rb | 23 ++++++++++++++++++----- 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 spec/show_spec.rb diff --git a/models/show.rb b/models/show.rb index 6c82f65..a3121aa 100644 --- a/models/show.rb +++ b/models/show.rb @@ -6,4 +6,6 @@ class Show < ActiveRecord::Base def to_s "#{name} airs at #{hour_of_day}:#{day_of_week}:00 on #{network} " end + + end diff --git a/spec/show_spec.rb b/spec/show_spec.rb new file mode 100644 index 0000000..cd983bf --- /dev/null +++ b/spec/show_spec.rb @@ -0,0 +1,13 @@ +require './db/setup' + + +describe '#search_by_day' do + it "should return Thursday shows" do + STDIN.stub(:gets).and_return("") + require_relative '../watchman' + shows = search_by_day('Thursday').map { |show| show.name } + puts shows + expect(shows).to eq(['Community','Homeland']) + end +end + \ No newline at end of file diff --git a/watchman.rb b/watchman.rb index ebe9be4..19d7b25 100644 --- a/watchman.rb +++ b/watchman.rb @@ -1,15 +1,28 @@ -require 'rubygems' -require 'bundler/setup' +# require 'rubygems' +# require 'bundler/setup' require "./db/setup" Dir.glob('./models/*').each { |r| require r} require "./db/seed" +def search_by_day(day) + Show.where(day_of_week: day) +end + puts "There are #{Show.count} in the database" +puts "What day of the week to search?" +day = STDIN.gets.chomp.capitalize +results = search_by_day(day) + + + Network.all.each do |network| puts "Shows airing on #{network}" - network.shows.each do |show| - puts show - end + results.each do |show| + puts show if show.network == network + end + # network.shows.each do |show| + # puts show + # end end From 4cddcd349605068afca11e6b50f3e0062b530971 Mon Sep 17 00:00:00 2001 From: noahpatterson Date: Thu, 2 Jan 2014 09:22:48 -0500 Subject: [PATCH 3/4] Eagle level. Add recipe table. Add to_s for pretty recipe print out. Add search by recipe name. --- db/migrate/201301020814_create_recipes.rb | 10 ++++++++++ db/seed.rb | 6 +++++- models/recipe.rb | 14 ++++++++++++++ spec/show_spec.rb | 1 - watchman.rb | 11 ++++++++--- 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 db/migrate/201301020814_create_recipes.rb create mode 100644 models/recipe.rb diff --git a/db/migrate/201301020814_create_recipes.rb b/db/migrate/201301020814_create_recipes.rb new file mode 100644 index 0000000..b991a59 --- /dev/null +++ b/db/migrate/201301020814_create_recipes.rb @@ -0,0 +1,10 @@ +class CreateRecipes < ActiveRecord::Migration + def change + create_table :recipes do |t| + t.string :name + t.text :ingredients + t.text :steps + t.timestamps + end + end +end \ No newline at end of file diff --git a/db/seed.rb b/db/seed.rb index 6aeb372..966d421 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1,6 +1,7 @@ # Cleaning Out Network.delete_all Show.delete_all +Recipe.delete_all amc = Network.create(name: "AMC") nbc = Network.create(name: "NBC") @@ -8,4 +9,7 @@ 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: "Hannibal", day_of_week: "Monday", hour_of_day: 20, network: nbc) -Show.create(name: "Homeland", day_of_week: "Thursday", hour_of_day: 20, network: showtime) \ No newline at end of file +Show.create(name: "Homeland", day_of_week: "Thursday", hour_of_day: 20, network: showtime) + +Recipe.create(name: "Hummus", ingredients: "chickpeas,tahini,olive oil,salt,lemon juice,garlic,cumin,water", steps: "Blend tahini and lemon juice.Add and blend olive oil, garlic, cumin and salt.Add and blend chickpeas.Add and blend water to desired consistency.") +Recipe.create(name: "Biscuits", ingredients: "flour,baking powder,salt,butter,milk", steps: "Mix flour, salt, and baking soda.Add butter and mix till butter is pea sized.Add milk and mix lightly.Flip onto a floured surface and pat down to desired thickness.Cut biscuits out of dough, reforming dough when necessary.Bake at 400 degrees for 12 minutes.") \ No newline at end of file diff --git a/models/recipe.rb b/models/recipe.rb new file mode 100644 index 0000000..3b11a59 --- /dev/null +++ b/models/recipe.rb @@ -0,0 +1,14 @@ +class Recipe < ActiveRecord::Base + validates_presence_of :name, :ingredients, :steps + + def to_s + puts "#{name}" + puts "Ingredients: #{ingredients.split(",")}" + puts "Steps:" + step_num = 1 + steps.split(".").each do |step| + puts "#{step_num}: #{step}\n" + step_num += 1 + end + end +end \ No newline at end of file diff --git a/spec/show_spec.rb b/spec/show_spec.rb index cd983bf..b60c29f 100644 --- a/spec/show_spec.rb +++ b/spec/show_spec.rb @@ -6,7 +6,6 @@ STDIN.stub(:gets).and_return("") require_relative '../watchman' shows = search_by_day('Thursday').map { |show| show.name } - puts shows expect(shows).to eq(['Community','Homeland']) end end diff --git a/watchman.rb b/watchman.rb index 19d7b25..528281a 100644 --- a/watchman.rb +++ b/watchman.rb @@ -22,7 +22,12 @@ def search_by_day(day) results.each do |show| puts show if show.network == network end - # network.shows.each do |show| - # puts show - # end end + +puts "Here are all the recipes" +Recipe.all.each { |recipe| recipe.to_s } + +puts "What recipe would you like to learn more about?" +recipe_search = STDIN.gets.chomp.capitalize +recipe_result = Recipe.where(name: recipe_search) +recipe_result.empty? ? puts("Sorry we cannot find that recipe") : recipe_result.each { |recipe| recipe.to_s } From a929c12f5d3aafec50d46bc3082947e0c4bca737 Mon Sep 17 00:00:00 2001 From: noahpatterson Date: Thu, 2 Jan 2014 12:26:01 -0500 Subject: [PATCH 4/4] Fix to_s to not output to console --- models/recipe.rb | 16 ++++++++-------- watchman.rb | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/models/recipe.rb b/models/recipe.rb index 3b11a59..db3461d 100644 --- a/models/recipe.rb +++ b/models/recipe.rb @@ -1,14 +1,14 @@ class Recipe < ActiveRecord::Base validates_presence_of :name, :ingredients, :steps + def pretty_steps + step_out = "" + steps.split(".").each_with_index { |step, step_num| step_out += "#{step_num+1}: #{step}\n"} + return step_out + end + + def to_s - puts "#{name}" - puts "Ingredients: #{ingredients.split(",")}" - puts "Steps:" - step_num = 1 - steps.split(".").each do |step| - puts "#{step_num}: #{step}\n" - step_num += 1 - end + "#{name}\nIngredients: #{ingredients.split(",")}\nSteps:\n#{pretty_steps}" end end \ No newline at end of file diff --git a/watchman.rb b/watchman.rb index 528281a..9de4168 100644 --- a/watchman.rb +++ b/watchman.rb @@ -25,9 +25,9 @@ def search_by_day(day) end puts "Here are all the recipes" -Recipe.all.each { |recipe| recipe.to_s } +Recipe.all.each { |recipe| puts recipe } puts "What recipe would you like to learn more about?" recipe_search = STDIN.gets.chomp.capitalize recipe_result = Recipe.where(name: recipe_search) -recipe_result.empty? ? puts("Sorry we cannot find that recipe") : recipe_result.each { |recipe| recipe.to_s } +recipe_result.empty? ? puts("Sorry we cannot find that recipe") : recipe_result.each { |recipe| puts recipe }