Class: CookbookClient::Recipe
- Inherits:
-
Object
- Object
- CookbookClient::Recipe
- Defined in:
- lib/cookbook_client/recipe.rb
Instance Attribute Summary collapse
-
#cook_method ⇒ Object
Returns the value of attribute cook_method.
-
#cook_time ⇒ Object
Returns the value of attribute cook_time.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#cuisine ⇒ Object
Returns the value of attribute cuisine.
-
#cuisine_id ⇒ Object
Returns the value of attribute cuisine_id.
-
#difficulty ⇒ Object
Returns the value of attribute difficulty.
-
#featured ⇒ Object
Returns the value of attribute featured.
-
#id ⇒ Object
Returns the value of attribute id.
-
#ingredients ⇒ Object
Returns the value of attribute ingredients.
-
#recipe_type ⇒ Object
Returns the value of attribute recipe_type.
-
#recipe_type_id ⇒ Object
Returns the value of attribute recipe_type_id.
-
#title ⇒ Object
Returns the value of attribute title.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Class Method Summary collapse
-
.all ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/MethodLength.
- .destroy(id) ⇒ Object
- .find(id) ⇒ Object
Instance Method Summary collapse
-
#initialize(info:) ⇒ Recipe
constructor
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
Constructor Details
#initialize(info:) ⇒ Recipe
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cookbook_client/recipe.rb', line 7 def initialize(info:) @title = info['title'] @cook_time = info['cook_time'] @cook_method = info['cook_method'] @ingredients = info['ingredients'] @difficulty = info['difficulty'] @recipe_type = info['recipe_type'] @cuisine = info['cuisine'] @id = info['id'] @created_at = info['created_at'] @updated_at = info['updated_at'] @cuisine_id = info['cuisine_id'] @recipe_type_id = info['recipe_type_id'] @featured = info['featured'] @user_id = info['user_id'] end |
Instance Attribute Details
#cook_method ⇒ Object
Returns the value of attribute cook_method.
2 3 4 |
# File 'lib/cookbook_client/recipe.rb', line 2 def cook_method @cook_method end |
#cook_time ⇒ Object
Returns the value of attribute cook_time.
2 3 4 |
# File 'lib/cookbook_client/recipe.rb', line 2 def cook_time @cook_time end |
#created_at ⇒ Object
Returns the value of attribute created_at.
2 3 4 |
# File 'lib/cookbook_client/recipe.rb', line 2 def created_at @created_at end |
#cuisine ⇒ Object
Returns the value of attribute cuisine.
2 3 4 |
# File 'lib/cookbook_client/recipe.rb', line 2 def cuisine @cuisine end |
#cuisine_id ⇒ Object
Returns the value of attribute cuisine_id.
2 3 4 |
# File 'lib/cookbook_client/recipe.rb', line 2 def cuisine_id @cuisine_id end |
#difficulty ⇒ Object
Returns the value of attribute difficulty.
2 3 4 |
# File 'lib/cookbook_client/recipe.rb', line 2 def difficulty @difficulty end |
#featured ⇒ Object
Returns the value of attribute featured.
2 3 4 |
# File 'lib/cookbook_client/recipe.rb', line 2 def featured @featured end |
#id ⇒ Object
Returns the value of attribute id.
2 3 4 |
# File 'lib/cookbook_client/recipe.rb', line 2 def id @id end |
#ingredients ⇒ Object
Returns the value of attribute ingredients.
2 3 4 |
# File 'lib/cookbook_client/recipe.rb', line 2 def ingredients @ingredients end |
#recipe_type ⇒ Object
Returns the value of attribute recipe_type.
2 3 4 |
# File 'lib/cookbook_client/recipe.rb', line 2 def recipe_type @recipe_type end |
#recipe_type_id ⇒ Object
Returns the value of attribute recipe_type_id.
2 3 4 |
# File 'lib/cookbook_client/recipe.rb', line 2 def recipe_type_id @recipe_type_id end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/cookbook_client/recipe.rb', line 2 def title @title end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
2 3 4 |
# File 'lib/cookbook_client/recipe.rb', line 2 def updated_at @updated_at end |
#user_id ⇒ Object
Returns the value of attribute user_id.
2 3 4 |
# File 'lib/cookbook_client/recipe.rb', line 2 def user_id @user_id end |
Class Method Details
.all ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/MethodLength
25 26 27 28 29 30 |
# File 'lib/cookbook_client/recipe.rb', line 25 def self.all CookbookClient.format_recipes( recipes: JSON.parse(CookbookClient.http.get('/api/v1/recipes/all').body), content_class: self ) end |
.destroy(id) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cookbook_client/recipe.rb', line 45 def self.destroy(id) response = CookbookClient.http.delete("/api/v1/recipes/#{id}") if response.status != 200 raise StandardError, "Error #{response.status} - #{response.body}" end CookbookClient.format_recipes( recipes: JSON.parse(response.body), content_class: self ).first end |
.find(id) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cookbook_client/recipe.rb', line 32 def self.find(id) response = CookbookClient.http.get("/api/v1/recipes/#{id}/search") if response.status != 200 raise StandardError, "Error #{response.status} - #{response.body}" end CookbookClient.format_recipes( recipes: JSON.parse(response.body), content_class: self ).first end |