Skip to content

completed panda, tiger, & eagle assignments #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions db/migrate/201303251230_create_recipes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateRecipes < ActiveRecord::Migration
def change
create_table :recipes do |t|
t.string :dish
t.string :ingredients
t.string :instructions
end
end
end
10 changes: 10 additions & 0 deletions db/seed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,15 @@
Show.delete_all
amc = Network.create(name: "AMC")
nbc = Network.create(name: "NBC")
cbs = Network.create(name: "CBS")
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: "60 Minutes", day_of_week: "Sunday", hour_of_day: 18, network: cbs)
Show.create(name: "Survivor", day_of_week: "Thursday", hour_of_day: 20, network: cbs)

Recipe.delete_all
Recipe.create(dish: "salsa", ingredients: "[tomatoes, jalapenos, cilantro, onions]", instructions: "chop and mix all ingredients together; season to taste")
Recipe.create(dish: "guacamole", ingredients: "[avocados, tomatoes, jalapeno, cilantro, onions, cumin]", instructions: "mash avocados; dice onions and tomatoes; mix all ingredients together; season to taste")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yum!

Recipe.create(dish: "lentil soup", ingredients: "[red lentils, onions, celery, tomatoes, herbs de provence]", instructions: "saute diced onions and celery in olive oil for 5 min; add red lentils, water, tomatoes, and spices; cook for 20 minutes")
Recipe.create(dish: "bruschetta", ingredients: "[bread, tomatoes, basil, red onions, basalmic vinegar]", instructions: "chop tomatoes, basil, red onions; add basalmic vinegar to mixture; serve with toasted bread")
Recipe.create(dish: "hummus", ingredients: "[chickpeas, tahini, garlic, olive oil]", instructions: "put all ingredients in blender and blend until it reaches smooth texture")
8 changes: 8 additions & 0 deletions models/recipe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Recipe < ActiveRecord::Base

validates_presence_of :dish

def to_s
"#{dish} has the following ingredients #{ingredients} "
end
end
30 changes: 27 additions & 3 deletions watchman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,34 @@
require "./db/seed"

puts "There are #{Show.count} in the database"
puts "What day of the week would you like to watch a show?"
day_of_week = gets.chomp

show_in_entered_day_of_week = false
Network.all.each do |network|
puts "Shows airing on #{network}"
network.shows.each do |show|
puts show
end
if show.day_of_week == day_of_week
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you have a loop that inside has an if statement, I recommend the following:

network.shows.to_a.select{|show| show.day_of_week == day_of_week} do |show|
  puts show
end

There's also the ability to do this in SQL:

Show.where(day_of_week: day_of_week).each do |show|
end

puts "#{show} on #{network}"
show_in_entered_day_of_week = true
end
end
end
puts "no shows air on #{day_of_week}" unless show_in_entered_day_of_week
puts "\n\n\n\n"


puts "These are the all the dishes in the database :"
Recipe.all.each do |recipe|
puts "#{recipe}"
end
puts "What would you like to make?"
dish = gets.chomp
recipe_exists = false
Recipe.all.each do |recipe|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, but I wouldn't recommend having the extra variable around (recipe_exists). Instead, maybe:

recipes = Recipe.where(dish: dish)
recipes.each do |recipe|
  puts recipe #and other stuff
end
puts "Sorry, #{dish} does not exist in the database" if recipes.blank?

if recipe.dish == dish
puts "This is how you make #{dish} :"
puts "#{recipe.instructions}"
recipe_exists = true
end
end
puts "Sorry, #{dish} does not exist in the database" unless recipe_exists