Class: Yummly::Recipe

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

Overview

This class maps a Yummly response to attributes on to a recipe object. Because the search and find API calls return recipe data slightly different structures, it also automatically rectifies these differences where possible.

When a response attribute is an array, collections of related objects will be created for convenience. For example, the “images” attribute on the response maps to the #images method which returns a collection of Yummlly::Image objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(recipe_json) ⇒ Recipe

Returns a new instance of Recipe.



11
12
13
# File 'lib/yummly/recipe.rb', line 11

def initialize(recipe_json)
  @response = recipe_json
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



9
10
11
# File 'lib/yummly/recipe.rb', line 9

def response
  @response
end

Instance Method Details

#attributeObject

Nutrition attribute’s search parameter name.



16
17
18
# File 'lib/yummly/recipe.rb', line 16

def attribute
  response["attribute"]
end

#attributesObject



20
21
22
# File 'lib/yummly/recipe.rb', line 20

def attributes
  response["attributes"]
end

#attributionObject



24
25
26
# File 'lib/yummly/recipe.rb', line 24

def attribution
  response["attribution"]
end

#descriptionObject



28
29
30
# File 'lib/yummly/recipe.rb', line 28

def description
  response["description"]
end

#flavorYummly::Flavor

Returns instance of a Yummly::Flavor object.

Returns:



33
34
35
# File 'lib/yummly/recipe.rb', line 33

def flavor
  @flavor ||= Yummly::Flavor.new(response["flavors"])
end

#idString

Returns the Yummly id for this recipe.

Returns:

  • (String)

    the Yummly id for this recipe.



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

def id
  response["id"]
end

#imagesArray

Returns collection of Yummly::Image objects.

Returns:

  • (Array)

    collection of Yummly::Image objects.



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

def images
  @images ||= images_node.collect { |image| Yummly::Image.new(image) }
end

#ingredient_linesArray

Returns collection of strings of ingredients.

Returns:

  • (Array)

    collection of strings of ingredients.



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

def ingredient_lines
  response["ingredientLines"]
end

#ingredientsArray

Returns collection of strings of ingredients.

Returns:

  • (Array)

    collection of strings of ingredients.



48
49
50
# File 'lib/yummly/recipe.rb', line 48

def ingredients
  response["ingredients"]
end

#nameString

Returns the name of the recipe, automatically finding it using the correct response node.

Returns:

  • (String)

    name of the recipe



59
60
61
# File 'lib/yummly/recipe.rb', line 59

def name
  response["name"] || recipe_name
end

#number_of_servingsInteger

Returns number of servings this recipe provides.

Returns:

  • (Integer)

    number of servings this recipe provides.



64
65
66
# File 'lib/yummly/recipe.rb', line 64

def number_of_servings
  response["numberOfServings"]
end

#nutrition_estimatesArray

The nutritional composition of the recipe, in the form of a list of nutrients and their amounts, per serving. We will return nutrition estimates only for those recipes where we are reasonably confident in their accuracy. These are only estimates and you should be clear about that in what you tell your users.

Returns:

  • (Array)

    collection of Yummly::NutritionEstimate objects.



72
73
74
# File 'lib/yummly/recipe.rb', line 72

def nutrition_estimates
  @nutrition_estimates ||= response["nutritionEstimates"].collect { |ne| Yummly::NutritionEstimate.new(ne) }
end

#ratingObject



76
77
78
# File 'lib/yummly/recipe.rb', line 76

def rating
  response["rating"]
end

#recipe_nameObject



80
81
82
# File 'lib/yummly/recipe.rb', line 80

def recipe_name
  response["recipeName"]
end

#total_timeObject



84
85
86
# File 'lib/yummly/recipe.rb', line 84

def total_time
  response["totalTime"]
end

#total_time_in_secondsObject



88
89
90
# File 'lib/yummly/recipe.rb', line 88

def total_time_in_seconds
  response["totalTimeInSeconds"]
end