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 3c028ff..966d421 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1,7 +1,15 @@ # Cleaning Out Network.delete_all Show.delete_all +Recipe.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) + +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..db3461d --- /dev/null +++ b/models/recipe.rb @@ -0,0 +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 + "#{name}\nIngredients: #{ingredients.split(",")}\nSteps:\n#{pretty_steps}" + end +end \ No newline at end of file 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..b60c29f --- /dev/null +++ b/spec/show_spec.rb @@ -0,0 +1,12 @@ +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 } + expect(shows).to eq(['Community','Homeland']) + end +end + \ No newline at end of file diff --git a/watchman.rb b/watchman.rb index ebe9be4..9de4168 100644 --- a/watchman.rb +++ b/watchman.rb @@ -1,15 +1,33 @@ -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 end + +puts "Here are all the recipes" +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| puts recipe }