Class: TopBeers::Style

Inherits:
Object
  • Object
show all
Defined in:
lib/top-beers/style.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#beersObject

Returns the value of attribute beers.



2
3
4
# File 'lib/top-beers/style.rb', line 2

def beers
  @beers
end

#nameObject (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

.allObject



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_beersObject



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