Class: TopBeers::Brewery
- Inherits:
-
Object
- Object
- TopBeers::Brewery
- Defined in:
- lib/top-beers/brewery.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#beers ⇒ Object
Returns the value of attribute beers.
-
#location_1 ⇒ Object
Returns the value of attribute location_1.
-
#location_2 ⇒ Object
Returns the value of attribute location_2.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#website ⇒ Object
Returns the value of attribute website.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name) ⇒ Brewery
constructor
A new instance of Brewery.
- #location ⇒ Object
- #show_beers ⇒ Object
Constructor Details
#initialize(name) ⇒ Brewery
Returns a new instance of Brewery.
7 8 9 10 11 |
# File 'lib/top-beers/brewery.rb', line 7 def initialize(name) @beers = [] @name = name @@all << self end |
Instance Attribute Details
#beers ⇒ Object
Returns the value of attribute beers.
2 3 4 |
# File 'lib/top-beers/brewery.rb', line 2 def beers @beers end |
#location_1 ⇒ Object
Returns the value of attribute location_1.
2 3 4 |
# File 'lib/top-beers/brewery.rb', line 2 def location_1 @location_1 end |
#location_2 ⇒ Object
Returns the value of attribute location_2.
2 3 4 |
# File 'lib/top-beers/brewery.rb', line 2 def location_2 @location_2 end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/top-beers/brewery.rb', line 3 def name @name end |
#website ⇒ Object
Returns the value of attribute website.
2 3 4 |
# File 'lib/top-beers/brewery.rb', line 2 def website @website end |
Class Method Details
.all ⇒ Object
44 45 46 |
# File 'lib/top-beers/brewery.rb', line 44 def self.all @@all.sort_by! { |e| e.name } end |
.find_or_create_by_name(name) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/top-beers/brewery.rb', line 13 def self.find_or_create_by_name(name) brewery = @@all.detect {|b| b.name.downcase == name.downcase} if brewery.nil? brewery = self.new(name) end brewery end |
Instance Method Details
#location ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/top-beers/brewery.rb', line 36 def location if @location_2.nil? "#{@location_1}" else "#{@location_1}, #{@location_2}" end end |
#show_beers ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/top-beers/brewery.rb', line 21 def show_beers puts "\n"+"-"*"#{@name}".length puts "#{@name}" puts "-"*"#{@name}".length if @website.nil? TopBeers::Scraper.scrape_details(@beers[0]) end puts "Location".underline + ": #{self.location}" puts "Website".underline + ": #{@website}" puts "Beers in the top 250".underline + ":" @beers.each.with_index(1) do |beer, i| puts "#{i}. #{beer.name} - #{beer.style.name}" end end |