Class: TopBeers::Style
- Inherits:
-
Object
- Object
- TopBeers::Style
- Defined in:
- lib/top-beers/style.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#beers ⇒ Object
Returns the value of attribute beers.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name) ⇒ Style
constructor
A new instance of Style.
- #show_beers ⇒ Object
Constructor Details
#initialize(name) ⇒ Style
Returns a new instance of Style.
7 8 9 10 11 |
# File 'lib/top-beers/style.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/style.rb', line 2 def beers @beers end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/top-beers/style.rb', line 3 def name @name end |
Class Method Details
.all ⇒ Object
30 31 32 |
# File 'lib/top-beers/style.rb', line 30 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/style.rb', line 13 def self.find_or_create_by_name(name) style = @@all.detect {|b| b.name.downcase == name.downcase} if style.nil? style = self.new(name) end style end |
Instance Method Details
#show_beers ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/top-beers/style.rb', line 21 def show_beers puts "\n"+"-"*"#{@name}".length puts "#{@name}" puts "-"*"#{@name}".length @beers.each.with_index(1) do |beer, i| puts "#{i}. #{beer.name} - #{beer.brewery.name}" end end |