Class: Recipe

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

Constant Summary collapse

@@all_recipes =

Parse JSON file into array

JSON.parse(file)
@@recipe_names =

Collect recipe names (array of strings) and ingredient lists (array of arrays of hashes)

[]
@@no_of_recipe =
@@recipe_names.length
@@ingredient_lists =
[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRecipe

Returns a new instance of Recipe.



39
40
# File 'lib/recipe.rb', line 39

def initialize
end

Class Method Details

.all_recipesObject



42
43
44
# File 'lib/recipe.rb', line 42

def self.all_recipes
  all_recipes_copy = @@all_recipes.dup
end

.ingredient_listsObject



54
55
56
# File 'lib/recipe.rb', line 54

def self.ingredient_lists
  @@ingredient_lists
end

.no_of_recipeObject



50
51
52
# File 'lib/recipe.rb', line 50

def self.no_of_recipe
  @@no_of_recipe
end

.recipe_namesObject



46
47
48
# File 'lib/recipe.rb', line 46

def self.recipe_names
  @@recipe_names
end

Instance Method Details

#display_recipe(recipe_index) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/recipe.rb', line 58

def display_recipe(recipe_index)
  recipe_box = ScreenMessage.new
  spacing = ScreenMessage::SPACING

  # Put all string output lines in a variable
  recipe = @@recipe_names[recipe_index].center(spacing, " ").upcase + "\n\n" + "*".colorize(:blue) * spacing + "\n\n"

  @@ingredient_lists[recipe_index].each do |list|
    list.each do |item, quantity|
      recipe += "#{item}".rjust(spacing * 0.6) + " x #{quantity}".ljust(spacing * 0.4) + "\n"
    end
  end

  # Format output using frame
  recipe_box.recipe_frame(recipe)
end