Class: DrinkAPI
- Inherits:
-
Object
- Object
- DrinkAPI
- Defined in:
- lib/LiquerY/DrinkAPI.rb
Instance Attribute Summary collapse
-
#id_array ⇒ Object
readonly
Returns the value of attribute id_array.
Instance Method Summary collapse
-
#initialize ⇒ DrinkAPI
constructor
A new instance of DrinkAPI.
- #make_hash ⇒ Object
Constructor Details
#initialize ⇒ DrinkAPI
Returns a new instance of DrinkAPI.
3 4 5 6 7 8 9 10 |
# File 'lib/LiquerY/DrinkAPI.rb', line 3 def initialize data = open("https://www.thecocktaildb.com/api/json/v1/1/filter.php?c=Cocktail").read doc = JSON.parse(data) #key is ["drinks"] value is array of ingredients @id_array = doc.first.last.each.with_object([]) do |id_hash, array| array << id_hash["idDrink"] end end |
Instance Attribute Details
#id_array ⇒ Object (readonly)
Returns the value of attribute id_array.
2 3 4 |
# File 'lib/LiquerY/DrinkAPI.rb', line 2 def id_array @id_array end |
Instance Method Details
#make_hash ⇒ Object
12 13 14 15 16 |
# File 'lib/LiquerY/DrinkAPI.rb', line 12 def make_hash self.id_array.each.with_object({}) do |id, drink_hash| drink_hash[id] = JSON.parse(open("https://www.thecocktaildb.com/api/json/v1/1/lookup.php?i=#{id}").read).values.first[0] end end |