Class: Yummly::Recipe

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(recipe_json) ⇒ Recipe

Returns a new instance of Recipe.



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

def initialize(recipe_json)
  @response = recipe_json
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#attributeObject

Nutrition attribute’s search parameter name.



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

def attribute
  response["attribute"]
end

#attributesObject



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

def attributes
  response["attributes"]
end

#attributionObject



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

def attribution
  @attribution ||= Yummly::Attribution.new(response["attribution"])
end

#descriptionObject



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

def description
  response["description"]
end

#flavorYummly::Flavor

Returns instance of a Yummly::Flavor object.

Returns:



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

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.



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

def id
  response["id"]
end

#imagesArray

Returns collection of Yummly::Image objects.

Returns:

  • (Array)

    collection of Yummly::Image objects.



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

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.



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

def ingredient_lines
  response["ingredientLines"]
end

#ingredientsArray

Returns collection of strings of ingredients.

Returns:

  • (Array)

    collection of strings of ingredients.



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

def ingredients
  response["ingredients"] || ingredient_lines
end

#nameString

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

Returns:

  • (String)

    name of the recipe



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

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.



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

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.



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

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

#ratingObject



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

def rating
  response["rating"]
end

#recipe_nameObject



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

def recipe_name
  response["recipeName"]
end

#thumbnailObject



93
94
95
96
97
# File 'lib/yummly/recipe.rb', line 93

def thumbnail
  if images
    images.first.small_url
  end
end

#total_timeObject



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

def total_time
  response["totalTime"]
end

#total_time_in_secondsObject



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

def total_time_in_seconds
  response["totalTimeInSeconds"]
end