Class: CoffeeHunt::CoffeeShop

Inherits:
Object
  • Object
show all
Defined in:
lib/Coffee_Hunt/coffee_shop.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#locationObject

defines attributes that are readable and writeable



41
42
43
# File 'lib/Coffee_Hunt/coffee_shop.rb', line 41

def location
  @location
end

#nameObject

defines attributes that are readable and writeable



41
42
43
# File 'lib/Coffee_Hunt/coffee_shop.rb', line 41

def name
  @name
end

#phoneObject

defines attributes that are readable and writeable



41
42
43
# File 'lib/Coffee_Hunt/coffee_shop.rb', line 41

def phone
  @phone
end

#priceObject

defines attributes that are readable and writeable



41
42
43
# File 'lib/Coffee_Hunt/coffee_shop.rb', line 41

def price
  @price
end

#ratingObject

defines attributes that are readable and writeable



41
42
43
# File 'lib/Coffee_Hunt/coffee_shop.rb', line 41

def rating
  @rating
end

Class Method Details

.allObject

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

#detailsObject

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.rating}    
  HEREDOC
end