Class: CoffeeHunt::CoffeeShop
- Inherits:
-
Object
- Object
- CoffeeHunt::CoffeeShop
- Defined in:
- lib/Coffee_Hunt/coffee_shop.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#location ⇒ Object
defines attributes that are readable and writeable.
-
#name ⇒ Object
defines attributes that are readable and writeable.
-
#phone ⇒ Object
defines attributes that are readable and writeable.
-
#price ⇒ Object
defines attributes that are readable and writeable.
-
#rating ⇒ Object
defines attributes that are readable and writeable.
Class Method Summary collapse
-
.all ⇒ Object
access to the @@all array aka my getter method.
-
.create_from_results(location_results) ⇒ Object
returns the collection of coffee shops.
-
.find_by_number(n) ⇒ Object
will return the coffee shop object.
-
.load_by_location(location) ⇒ Object
returns my array of coffee shops.
Instance Method Summary collapse
-
#details ⇒ Object
will display the information about the coffee shops.
-
#initialize(attributes = {}) ⇒ CoffeeShop
constructor
A new instance of CoffeeShop.
Constructor Details
#initialize(attributes = {}) ⇒ CoffeeShop
Returns a new instance of CoffeeShop.
43 44 45 46 47 48 49 50 |
# File 'lib/Coffee_Hunt/coffee_shop.rb', line 43 def initialize(attributes={}) # binding.pry attributes.each do |attribute_name,attribute_value| if self.respond_to?("#{attribute_name}=") self.send("#{attribute_name}=", attribute_value) end end end |
Instance Attribute Details
#location ⇒ Object
defines attributes that are readable and writeable
41 42 43 |
# File 'lib/Coffee_Hunt/coffee_shop.rb', line 41 def location @location end |
#name ⇒ Object
defines attributes that are readable and writeable
41 42 43 |
# File 'lib/Coffee_Hunt/coffee_shop.rb', line 41 def name @name end |
#phone ⇒ Object
defines attributes that are readable and writeable
41 42 43 |
# File 'lib/Coffee_Hunt/coffee_shop.rb', line 41 def phone @phone end |
#price ⇒ Object
defines attributes that are readable and writeable
41 42 43 |
# File 'lib/Coffee_Hunt/coffee_shop.rb', line 41 def price @price end |
#rating ⇒ Object
defines attributes that are readable and writeable
41 42 43 |
# File 'lib/Coffee_Hunt/coffee_shop.rb', line 41 def @rating end |
Class Method Details
.all ⇒ Object
access to the @@all array aka my getter method
8 9 10 |
# File 'lib/Coffee_Hunt/coffee_shop.rb', line 8 def self.all #access to the @@all array aka my getter method @@all end |
.create_from_results(location_results) ⇒ Object
returns the collection of coffee shops
22 23 24 25 26 |
# File 'lib/Coffee_Hunt/coffee_shop.rb', line 22 def self.create_from_results(location_results) #returns the collection of coffee shops location_results.map do |coffee_shop_hash| self.new(coffee_shop_hash) end end |
.find_by_number(n) ⇒ Object
will return the coffee shop object
28 29 30 |
# File 'lib/Coffee_Hunt/coffee_shop.rb', line 28 def self.find_by_number(n) # will return the coffee shop object @@all[n.to_i-1] end |
.load_by_location(location) ⇒ Object
returns my array of coffee shops
12 13 14 15 16 17 18 19 20 |
# File 'lib/Coffee_Hunt/coffee_shop.rb', line 12 def self.load_by_location(location) # returns my array of coffee shops location_results = API.yelp_search("coffee shop", location) if location_results != nil @@all = self.create_from_results(location_results) else @@all = [] end # binding.pry end |
Instance Method Details
#details ⇒ Object
will display the information about the coffee shops
32 33 34 35 36 37 38 39 |
# File 'lib/Coffee_Hunt/coffee_shop.rb', line 32 def details #will display the information about the coffee shops <<-HEREDOC #{self.name.colorize(:yellow)} #{self.location["display_address"].join("\n")} #{self.phone} Rating:#{self.} HEREDOC end |