Class: CookbookClient::Cuisine
- Inherits:
-
Object
- Object
- CookbookClient::Cuisine
- Defined in:
- lib/cookbook_client/cuisine.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(info:) ⇒ Cuisine
constructor
A new instance of Cuisine.
Constructor Details
#initialize(info:) ⇒ Cuisine
Returns a new instance of Cuisine.
4 5 6 7 |
# File 'lib/cookbook_client/cuisine.rb', line 4 def initialize(info:) @id = info['id'] @name = info['name'] end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
2 3 4 |
# File 'lib/cookbook_client/cuisine.rb', line 2 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/cookbook_client/cuisine.rb', line 2 def name @name end |
Class Method Details
.all ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/cookbook_client/cuisine.rb', line 9 def self.all response = CookbookClient.http.get('/api/v1/cuisines') if response.status != 200 raise StandardError, "Error #{response.status} - #{response.body}" end format_cuisines cuisines: JSON.parse(response.body) end |
.find_by_name(name) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/cookbook_client/cuisine.rb', line 19 def self.find_by_name(name) response = CookbookClient.http.get('/api/v1/cuisines/name', name: name) if response.status != 200 raise StandardError, "Error #{response.status} - #{response.body}" end format_cuisines(cuisines: JSON.parse(response.body)).first end |
.format_cuisines(cuisines:) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/cookbook_client/cuisine.rb', line 29 def self.format_cuisines(cuisines:) cuisines = [cuisines] unless cuisines.is_a? Array cuisines.map do |c| new info: c end end |