Class: Yummly::Recipe
- Inherits:
-
Object
- Object
- Yummly::Recipe
- 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
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
-
#attribute ⇒ Object
Nutrition attribute’s search parameter name.
- #attributes ⇒ Object
- #attribution ⇒ Object
- #description ⇒ Object
-
#flavor ⇒ Yummly::Flavor
Instance of a Yummly::Flavor object.
-
#id ⇒ String
The Yummly id for this recipe.
-
#images ⇒ Array
Collection of Yummly::Image objects.
-
#ingredient_lines ⇒ Array
Collection of strings of ingredients.
-
#ingredients ⇒ Array
Collection of strings of ingredients.
-
#initialize(recipe_json) ⇒ Recipe
constructor
A new instance of Recipe.
-
#name ⇒ String
Returns the name of the recipe, automatically finding it using the correct response node.
-
#number_of_servings ⇒ Integer
Number of servings this recipe provides.
-
#nutrition_estimates ⇒ Array
The nutritional composition of the recipe, in the form of a list of nutrients and their amounts, per serving.
- #rating ⇒ Object
- #recipe_name ⇒ Object
- #total_time ⇒ Object
- #total_time_in_seconds ⇒ Object
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
#response ⇒ Object
Returns the value of attribute response.
9 10 11 |
# File 'lib/yummly/recipe.rb', line 9 def response @response end |
Instance Method Details
#attribute ⇒ Object
Nutrition attribute’s search parameter name.
16 17 18 |
# File 'lib/yummly/recipe.rb', line 16 def attribute response["attribute"] end |
#attributes ⇒ Object
20 21 22 |
# File 'lib/yummly/recipe.rb', line 20 def attributes response["attributes"] end |
#attribution ⇒ Object
24 25 26 |
# File 'lib/yummly/recipe.rb', line 24 def attribution response["attribution"] end |
#description ⇒ Object
28 29 30 |
# File 'lib/yummly/recipe.rb', line 28 def description response["description"] end |
#flavor ⇒ Yummly::Flavor
Returns instance of a Yummly::Flavor object.
33 34 35 |
# File 'lib/yummly/recipe.rb', line 33 def flavor @flavor ||= Yummly::Flavor.new(response["flavors"]) end |
#id ⇒ String
Returns the Yummly id for this recipe.
38 39 40 |
# File 'lib/yummly/recipe.rb', line 38 def id response["id"] end |
#images ⇒ Array
Returns 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_lines ⇒ Array
Returns collection of strings of ingredients.
53 54 55 |
# File 'lib/yummly/recipe.rb', line 53 def ingredient_lines response["ingredientLines"] end |
#ingredients ⇒ Array
Returns collection of strings of ingredients.
48 49 50 |
# File 'lib/yummly/recipe.rb', line 48 def ingredients response["ingredients"] end |
#name ⇒ String
Returns the name of the recipe, automatically finding it using the correct response node.
59 60 61 |
# File 'lib/yummly/recipe.rb', line 59 def name response["name"] || recipe_name end |
#number_of_servings ⇒ Integer
Returns number of servings this recipe provides.
64 65 66 |
# File 'lib/yummly/recipe.rb', line 64 def number_of_servings response["numberOfServings"] end |
#nutrition_estimates ⇒ Array
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.
72 73 74 |
# File 'lib/yummly/recipe.rb', line 72 def nutrition_estimates @nutrition_estimates ||= response["nutritionEstimates"].collect { |ne| Yummly::NutritionEstimate.new(ne) } end |
#rating ⇒ Object
76 77 78 |
# File 'lib/yummly/recipe.rb', line 76 def response["rating"] end |
#recipe_name ⇒ Object
80 81 82 |
# File 'lib/yummly/recipe.rb', line 80 def recipe_name response["recipeName"] end |
#total_time ⇒ Object
84 85 86 |
# File 'lib/yummly/recipe.rb', line 84 def total_time response["totalTime"] end |
#total_time_in_seconds ⇒ Object
88 89 90 |
# File 'lib/yummly/recipe.rb', line 88 def total_time_in_seconds response["totalTimeInSeconds"] end |