Class: JustTheRecipe::Recipe

Inherits:
Object
  • Object
show all
Defined in:
lib/just-the-recipe/recipe.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#cookbookObject

Returns the value of attribute cookbook.



3
4
5
# File 'lib/just-the-recipe/recipe.rb', line 3

def cookbook
  @cookbook
end

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/just-the-recipe/recipe.rb', line 3

def description
  @description
end

#ingredientsObject

Returns the value of attribute ingredients.



3
4
5
# File 'lib/just-the-recipe/recipe.rb', line 3

def ingredients
  @ingredients
end

#stepsObject

Returns the value of attribute steps.



3
4
5
# File 'lib/just-the-recipe/recipe.rb', line 3

def steps
  @steps
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/just-the-recipe/recipe.rb', line 3

def title
  @title
end

#urlObject

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

.allObject



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_recipeObject



39
40
41
# File 'lib/just-the-recipe/recipe.rb', line 39

def display_recipe
    puts "#{return_recipe}"
end

#return_ingredientsObject



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_recipeObject



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_stepsObject



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