-
Notifications
You must be signed in to change notification settings - Fork 27
Panda,tiger and eagle #28
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
base: master
Are you sure you want to change the base?
Changes from all commits
15edf6a
7876db6
4cddcd3
a929c12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is perfectly fine --- though I prefer limiting my results and then acting upon then. results.select{|s| s.network == network}.each do
puts show
end There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, also --- ActiveRecord provides some methods for free... Since this exists: class Network < ActiveRecord::Base
has_many :shows
#..snip
end We could do: Network.all.each do |network|
puts "Shows airing on #{network}"
network.shows.each do |show|
puts show
end
end There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand what you mean by your second comment, the above outputs all the shows. Wasn't the goal to only output the search results? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @noahpatterson --- yes, that was the requirement, and you did accomplish that. My point -- in |
||
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 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done!
Though it sort of shows we should be using an abstraction for STDIN, like highline or similar