Class: Food
- Inherits:
-
Object
- Object
- Food
- Defined in:
- lib/food.rb
Overview
Represents single recipe from Yummly
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
the id of the recipe on Yummly.
Instance Method Summary collapse
-
#image_url(food_json) ⇒ String
Extract image from json.
-
#initialize(food_json) ⇒ Food
constructor
Creates food with the parameters from JSON.
-
#to_str ⇒ String
Provides stats of the user in human-readble form.
Constructor Details
#initialize(food_json) ⇒ Food
Creates food with the parameters from JSON
9 10 11 12 13 14 15 16 |
# File 'lib/food.rb', line 9 def initialize(food_json) @name = food_json['name'] @id = food_json['id'] @aprox_time = food_json['totalTime'] @image_url = image_url food_json @ingredients = food_json['ingredientLines'] @guide_url = food_json['source']['sourceRecipeUrl'] end |
Instance Attribute Details
#id ⇒ Object (readonly)
the id of the recipe on Yummly
4 5 6 |
# File 'lib/food.rb', line 4 def id @id end |
Instance Method Details
#image_url(food_json) ⇒ String
Extract image from json
22 23 24 25 26 |
# File 'lib/food.rb', line 22 def image_url(food_json) url = food_json['images'][0]['hostedLargeUrl'] url = 'Sorry, I can not provide you picture of this food' if url.nil? url end |
#to_str ⇒ String
Provides stats of the user in human-readble form
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/food.rb', line 31 def to_str result = @name result += "\nID: #{@id}" result += "\n\nApproximate time: #{@aprox_time}" result += "\nImage URL: #{@image_url}\n" result += "\nIngredients:\n" result += @ingredients.join("\n") result += "\n\nStep-by-step: #{@guide_url}\n" result end |