Giter VIP home page Giter VIP logo

pantry_1911's Introduction

Pantry

Instructions

  • Fork this Repository

  • Clone your forked repo to your computer.

  • Complete the activity below.

  • Push your solution to your forked repo

  • Submit a pull request from your repository to this repository

    • Put your name in your PR!

    Iteration 1

    Use TDD to build an Ingredient class with the following attributes:

    • name - the name of the ingredient
    • unit - the unit in which the ingredient is measured
    • calories - the amount of calories per unit of the ingredient.

    The Ingredient class should respond to the following interaction pattern:

    pry(main)> require './lib/ingredient'
    # => true
    
    pry(main)> ingredient = Ingredient.new("Cheese", "oz", 50)
    # => #<Ingredient:0x007fe6041273d8...>
    
    pry(main)> ingredient.name
    # => "Cheese"
    
    pry(main)> ingredient.unit
    # => "oz"
    
    pry(main)> ingredient.calories
    # => 50

    Iteration 2

    Use TDD to build a Recipe class that responds to the following interaction pattern.

    For the add_ingredient method, the first argument is an Ingredient, and the second argument is the amount of the ingredient required for the Recipe.

    The total_calories method should sum the calories of each ingredient. The calories for each ingredient can be calculated by multiplying the calories attribute of the Ingredient by the amount of the ingredient required for the recipe.

    pry(main)> require './lib/ingredient'
    # => true
    
    pry(main)> require './lib/recipe'
    # => true
    
    pry(main)> ingredient1 = Ingredient.new("Cheese", "C", 100)
    # => #<Ingredient:0x007fe8438c7a70...>
    
    pry(main)> ingredient2 = Ingredient.new("Macaroni", "oz", 30)
    # => #<Ingredient:0x007fe843857f40...>
    
    pry(main)> recipe = Recipe.new("Mac and Cheese")
    # => #<Recipe:0x007fe84383d000...>
    
    pry(main)> recipe.name
    # => "Mac and Cheese"
    
    pry(main)> recipe.ingredients_required
    # => {}
    
    pry(main)> recipe.add_ingredient(ingredient1, 2)
    
    pry(main)> recipe.add_ingredient(ingredient2, 8)
    
    pry(main)> recipe.ingredients_required
    # => {#<Ingredient:0x00007fd7811553c8...> => 2, #<Ingredient:0x00007fd78110b0e8...> => 8}
    
    pry(main)> recipe.amount_required(ingredient1)
    # => 2
    
    pry(main)> recipe.amount_required(ingredient2)       
    # => 8
    
    pry(main)> recipe.ingredients
    # => [#<Ingredient:0x007fe8438c7a70...>, #<Ingredient:0x007fe843857f40...>]
    
    pry(main)> recipe.total_calories
    # => 440

    Iteration 3

    Use TDD to build a Pantry class that responds to the following interaction pattern:

    pry(main)> require './lib/pantry'
    # => true
    
    pry(main)> require './lib/ingredient'
    # => true
    
    pry(main)> require './lib/recipe'
    # => true
    
    pry(main)> pantry = Pantry.new
    # => #<Pantry:0x007fd8858863b8...>
    
    pry(main)> ingredient1 = Ingredient.new("Cheese", "C", 50)
    # => #<Ingredient:0x007fd885846e20...>
    
    pry(main)> ingredient2 = Ingredient.new("Macaroni", "oz", 200)
    # => #<Ingredient:0x007fd88582ed98...>
    
    pry(main)> recipe = Recipe.new("Mac and Cheese")
    # => #<Recipe:0x007fd885050fe0...>
    
    pry(main)> recipe.add_ingredient(ingredient1, 2)
    
    pry(main)> recipe.add_ingredient(ingredient2, 8)
    
    pry(main)> pantry.stock
    # => {}
    
    pry(main)> pantry.stock_check(ingredient1)
    # => 0
    
    pry(main)> pantry.restock(ingredient1, 5)
    
    pry(main)> pantry.restock(ingredient1, 10)
    
    pry(main)> pantry.stock_check(ingredient1)
    # => 15
    
    pry(main)> pantry.enough_ingredients_for?(recipe)
    # => false
    
    pry(main)> pantry.restock(ingredient2, 7)
    
    pry(main)> pantry.enough_ingredients_for?(recipe)
    # => false
    
    pry(main)> pantry.restock(ingredient2, 1)
    
    pry(main)> pantry.enough_ingredients_for?(recipe)
    # => true

    Iteration 4

    Use TDD to build a CookBook class that responds to the following interaction pattern.

    For the summary, ingredients are listed in order of calories. This is the amount of calories that ingredient contributes to the total calories of the recipe, not the amount of calories per single unit of the ingredient.

    pry(main)> require './lib/cook_book'
    # => true
    
    pry(main)> require './lib/ingredient'
    # => true
    
    pry(main)> require './lib/recipe'
    # => true
    
    pry(main)> cookbook = CookBook.new
    # => #<CookBook:0x00007faae6a42228 @recipes=[]>
    
    pry(main)> ingredient1 = Ingredient.new("Cheese", "C", 100)
    # => #<Ingredient:0x00007faae6a207e0...>
    
    pry(main)> ingredient2 = Ingredient.new("Macaroni", "oz", 30)
    # => #<Ingredient:0x00007faae69e3cf0...>
    
    pry(main)> recipe1 = Recipe.new("Mac and Cheese")
    # => #<Recipe:0x00007faae69c9698...>
    
    pry(main)> recipe1.add_ingredient(ingredient1, 2)
    
    pry(main)> recipe1.add_ingredient(ingredient2, 8)
    
    pry(main)> ingredient3 = Ingredient.new("Ground Beef", "oz", 100)
    # => #<Ingredient:0x00007faae6950860...>
    
    pry(main)> ingredient4 = Ingredient.new("Bun", "g", 1)
    # => #<Ingredient:0x00007faae694bb80...>
    
    pry(main)> recipe2 = Recipe.new("Burger")
    # => #<Recipe:0x00007faae692a110...>
    
    pry(main)> recipe2.add_ingredient(ingredient3, 4)
    
    pry(main)> recipe2.add_ingredient(ingredient4, 100)
    
    pry(main)> cookbook.add_recipe(recipe1)
    
    pry(main)> cookbook.add_recipe(recipe2)
    
    pry(main)> cookbook.summary
    # => [{:name=>"Mac and Cheese", :details=>{:ingredients=>[{:ingredient=>"Macaroni", :amount=>"8 oz"}, {:ingredient=>"Cheese", :amount=>"2 C"}], :total_calories=>440}}, {:name=>"Burger", :details=>{:ingredients=>[{:ingredient=>"Ground Beef", :amount=>"4 oz"}, {:ingredient=>"Bun", :amount=>"100 g"}], :total_calories=>500}}]

pantry_1911's People

Contributors

benfox1216 avatar memcmahon avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.