-
-
Save TGSmith/871868f40d3fb108ac30 to your computer and use it in GitHub Desktop.
Bernie's Bistro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
class Recipe | |
attr_reader :id, :name, :description, :ingredients, :directions | |
def initialize(data={}) | |
@id = data[:id] | |
@name = data[:name] | |
@description = data[:description] | |
@ingredients = data[:ingredients] | |
@directions = data[:directions] | |
end | |
# I need to finish this before I give Bernie the program... | |
def to_s | |
<<-TEXT | |
#{id} - #{name} | |
#{description} | |
Ingredients: | |
#{ingredients} | |
Preparation Instructions: | |
#{directions} | |
TEXT | |
end | |
end | |
class Bistro | |
def initialize | |
@recipes = [] | |
end | |
def load_recipes(filename) | |
CSV.foreach(filename, {:headers => true, :header_converters => :symbol}) do |row| | |
@recipes << Recipe.new(row) | |
end | |
end | |
# I need to finish this before I give Bernie the program... | |
def list_recipes | |
@recipes.each do |recipe| | |
puts "#{recipe.id}. #{recipe.name}" | |
end | |
end | |
# The CSV file looks like this: | |
# "id", "name", "description", "ingredients", "directions" | |
def find_recipe_by_id(recipe_id) | |
# raise "Can't find a recipe with an id of #{recipe_id.inspect}" unless @recipes | |
recipes = [] | |
@recipes.each do |recipe| | |
recipes << recipe if recipes.id == recipe_id | |
end | |
puts recipes | |
end | |
end | |
if ARGV.any? | |
# I wonder if I could clean this up... | |
bistro = Bistro.new | |
bistro.load_recipes("recipes.csv") | |
if ARGV[0] == "list" | |
bistro.list_recipes | |
elsif ARGV[0] == "display" | |
bistro.find_recipe_by_id(ARGV[1]) | |
else | |
puts "no recipe found" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative('bistro') | |
# Your driver code here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
id | name | description | ingredients | directions | |
---|---|---|---|---|---|
1 | Kale Burger | Combining the taste of cow with the nutrition of kale! | Kale, Cow | Preheat oven to 500 degrees, put in a cow. Wait 10 minutes. Put in some kale. Take out cow and kale. Put on bun. Serve HOT! | |
2 | Poodle Cake (For your puppy!) | Poople cakes! Perfect for pet poodle! | Kibble, Hot dogs | Mix kibble with hot dog. Bake at 500 degrees for 25 minutes. DO NOT ADD CHOCOLATE | |
3 | Peanut Butter Coffee Brownie | Just looking has caused people to gain 10 pounds! | Chocolate, Peanut Butter, Espresso, Cream Cheese | Chew the espresso beans to a pulp, spit them into the bowl. Now mix in the chocolate, cream cheese, and peanut butter. Bake at 450 for 45 minutes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment