Class: JustTheRecipe::Recipe
- Inherits:
-
Object
- Object
- JustTheRecipe::Recipe
- Defined in:
- lib/just-the-recipe/recipe.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#cookbook ⇒ Object
Returns the value of attribute cookbook.
-
#description ⇒ Object
Returns the value of attribute description.
-
#ingredients ⇒ Object
Returns the value of attribute ingredients.
-
#steps ⇒ Object
Returns the value of attribute steps.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #add_to_cookbook(name) ⇒ Object
- #display_recipe ⇒ Object
-
#initialize(title, description, ingredients, steps, url = "n/a") ⇒ Recipe
constructor
ingredients and steps are arrays.
- #return_ingredients ⇒ Object
- #return_recipe ⇒ Object
- #return_steps ⇒ Object
Constructor Details
#initialize(title, description, ingredients, steps, url = "n/a") ⇒ Recipe
ingredients and steps are arrays
7 8 9 10 11 12 13 |
# File 'lib/just-the-recipe/recipe.rb', line 7 def initialize(title, description, ingredients, steps, url= "n/a") # ingredients and steps are arrays @title = title @description = description @ingredients = ingredients @steps = steps @url = url end |
Instance Attribute Details
#cookbook ⇒ Object
Returns the value of attribute cookbook.
3 4 5 |
# File 'lib/just-the-recipe/recipe.rb', line 3 def cookbook @cookbook end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/just-the-recipe/recipe.rb', line 3 def description @description end |
#ingredients ⇒ Object
Returns the value of attribute ingredients.
3 4 5 |
# File 'lib/just-the-recipe/recipe.rb', line 3 def ingredients @ingredients end |
#steps ⇒ Object
Returns the value of attribute steps.
3 4 5 |
# File 'lib/just-the-recipe/recipe.rb', line 3 def steps @steps end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/just-the-recipe/recipe.rb', line 3 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/just-the-recipe/recipe.rb', line 3 def url @url end |
Class Method Details
.all ⇒ Object
15 16 17 |
# File 'lib/just-the-recipe/recipe.rb', line 15 def self.all @@all end |
Instance Method Details
#add_to_cookbook(name) ⇒ Object
43 44 45 46 |
# File 'lib/just-the-recipe/recipe.rb', line 43 def add_to_cookbook(name) self.cookbook = JustTheRecipe::Cookbook.find_or_create_by_name(name) self.cookbook.write_recipe_to_cookbook(self) end |
#display_recipe ⇒ Object
39 40 41 |
# File 'lib/just-the-recipe/recipe.rb', line 39 def display_recipe puts "#{return_recipe}" end |
#return_ingredients ⇒ Object
23 24 25 26 27 |
# File 'lib/just-the-recipe/recipe.rb', line 23 def return_ingredients string = "" @ingredients.each{|i| string<< "• #{i}\n"} string end |
#return_recipe ⇒ Object
19 20 21 |
# File 'lib/just-the-recipe/recipe.rb', line 19 def return_recipe "\nRecipe: #{@title}\nDescription: #{@description}\nIngredients:\n#{self.return_ingredients}Steps:\n#{self.return_steps}Source URL: #{self.url}\n***********************\n" end |
#return_steps ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/just-the-recipe/recipe.rb', line 29 def return_steps string = "" step_count = 1 @steps.each do |i| string << " #{step_count}. #{i}\n" step_count += 1 end string end |