Class: MaBreweries::BREWERY

Inherits:
Object
  • Object
show all
Defined in:
lib/ma_breweries/brewery.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ BREWERY

Returns a new instance of BREWERY.



6
7
8
9
10
11
12
13
# File 'lib/ma_breweries/brewery.rb', line 6

def initialize(attributes)
  attributes.each do |key, value|
    if self.respond_to?(key)
    self.send(("#{key}="), value)
    end
  end
  @@all << self
end

Instance Attribute Details

#brewery_typeObject

Returns the value of attribute brewery_type.



3
4
5
# File 'lib/ma_breweries/brewery.rb', line 3

def brewery_type
  @brewery_type
end

#cityObject

Returns the value of attribute city.



3
4
5
# File 'lib/ma_breweries/brewery.rb', line 3

def city
  @city
end

#countryObject

Returns the value of attribute country.



3
4
5
# File 'lib/ma_breweries/brewery.rb', line 3

def country
  @country
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/ma_breweries/brewery.rb', line 3

def name
  @name
end

#phoneObject

Returns the value of attribute phone.



3
4
5
# File 'lib/ma_breweries/brewery.rb', line 3

def phone
  @phone
end

#postal_codeObject

Returns the value of attribute postal_code.



3
4
5
# File 'lib/ma_breweries/brewery.rb', line 3

def postal_code
  @postal_code
end

#stateObject

Returns the value of attribute state.



3
4
5
# File 'lib/ma_breweries/brewery.rb', line 3

def state
  @state
end

#streetObject

Returns the value of attribute street.



3
4
5
# File 'lib/ma_breweries/brewery.rb', line 3

def street
  @street
end

#website_urlObject

Returns the value of attribute website_url.



3
4
5
# File 'lib/ma_breweries/brewery.rb', line 3

def website_url
  @website_url
end

Class Method Details

.allObject



15
16
17
# File 'lib/ma_breweries/brewery.rb', line 15

def self.all
    @@all
end

.all_namesObject



19
20
21
22
23
# File 'lib/ma_breweries/brewery.rb', line 19

def self.all_names
  self.all.each_with_index do |brewery, i|
  puts "#{i+1}: #{brewery.name}"
  end
end

.find_by_brewery_type(brewery_type) ⇒ Object



30
31
32
# File 'lib/ma_breweries/brewery.rb', line 30

def self.find_by_brewery_type(brewery_type)
  self.all.select {|brewery| brewery.brewery_type.downcase == brewery_type.downcase}
end

.find_by_city(city) ⇒ Object

def self.find_by_street(street)

self.all.select {|brewery| brewery.street.downcase == street.downcase}

end



38
39
40
# File 'lib/ma_breweries/brewery.rb', line 38

def self.find_by_city(city)
  self.all.select {|brewery| brewery.city.downcase == city.downcase}
end

.find_by_name(name) ⇒ Object



25
26
27
28
# File 'lib/ma_breweries/brewery.rb', line 25

def self.find_by_name(name)
  self.all.detect {|brewery| brewery.name.downcase == name.downcase}

end

Instance Method Details

#brew_infoObject



48
49
50
51
52
53
54
# File 'lib/ma_breweries/brewery.rb', line 48

def brew_info
  puts "Brewery Name: #{self.name}"
  puts "Brewery Type: #{self.brewery_type}"
  puts "Adress: #{self.street} #{self.city} #{self.state}, #{self.postal_code} #{self.country}"
  puts "Phone Number: #{self.phone}"
  puts "Website: #{self.website_url}"
end