Class: BeerAdvocate::Beer
- Inherits:
-
Object
- Object
- BeerAdvocate::Beer
- Defined in:
- lib/beer_advocate/beer.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#abv ⇒ Object
Returns the value of attribute abv.
-
#brewery ⇒ Object
Returns the value of attribute brewery.
-
#brewery_url ⇒ Object
Returns the value of attribute brewery_url.
-
#name ⇒ Object
Returns the value of attribute name.
-
#name_url ⇒ Object
Returns the value of attribute name_url.
-
#review_count ⇒ Object
Returns the value of attribute review_count.
-
#score ⇒ Object
Returns the value of attribute score.
-
#style ⇒ Object
Returns the value of attribute style.
-
#style_url ⇒ Object
Returns the value of attribute style_url.
Class Method Summary collapse
- .all ⇒ Object
- .create_from_collection(beers_array) ⇒ Object
- .find_beer(beer_hash) ⇒ Object
- .find_or_create_from_collection(beers_array) ⇒ Object
Instance Method Summary collapse
-
#initialize(beer_hash) ⇒ Beer
constructor
A new instance of Beer.
Constructor Details
#initialize(beer_hash) ⇒ Beer
Returns a new instance of Beer.
27 28 29 30 |
# File 'lib/beer_advocate/beer.rb', line 27 def initialize(beer_hash) beer_hash.each {|key, value| self.send(("#{key}="), value)} @@all << self end |
Instance Attribute Details
#abv ⇒ Object
Returns the value of attribute abv.
2 3 4 |
# File 'lib/beer_advocate/beer.rb', line 2 def abv @abv end |
#brewery ⇒ Object
Returns the value of attribute brewery.
2 3 4 |
# File 'lib/beer_advocate/beer.rb', line 2 def brewery @brewery end |
#brewery_url ⇒ Object
Returns the value of attribute brewery_url.
2 3 4 |
# File 'lib/beer_advocate/beer.rb', line 2 def brewery_url @brewery_url end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/beer_advocate/beer.rb', line 2 def name @name end |
#name_url ⇒ Object
Returns the value of attribute name_url.
2 3 4 |
# File 'lib/beer_advocate/beer.rb', line 2 def name_url @name_url end |
#review_count ⇒ Object
Returns the value of attribute review_count.
2 3 4 |
# File 'lib/beer_advocate/beer.rb', line 2 def review_count @review_count end |
#score ⇒ Object
Returns the value of attribute score.
2 3 4 |
# File 'lib/beer_advocate/beer.rb', line 2 def score @score end |
#style ⇒ Object
Returns the value of attribute style.
2 3 4 |
# File 'lib/beer_advocate/beer.rb', line 2 def style @style end |
#style_url ⇒ Object
Returns the value of attribute style_url.
2 3 4 |
# File 'lib/beer_advocate/beer.rb', line 2 def style_url @style_url end |
Class Method Details
.all ⇒ Object
38 39 40 |
# File 'lib/beer_advocate/beer.rb', line 38 def self.all @@all end |
.create_from_collection(beers_array) ⇒ Object
32 33 34 35 36 |
# File 'lib/beer_advocate/beer.rb', line 32 def self.create_from_collection(beers_array) beers_array.each do |beer_hash| BeerAdvocate::Beer.new(beer_hash) end end |
.find_beer(beer_hash) ⇒ Object
42 43 44 |
# File 'lib/beer_advocate/beer.rb', line 42 def self.find_beer(beer_hash) self.all.find {|beer| beer.name == beer_hash[:name] && beer.brewery == beer_hash[:brewery]} end |
.find_or_create_from_collection(beers_array) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/beer_advocate/beer.rb', line 46 def self.find_or_create_from_collection(beers_array) beers_array.each do |beer_hash| if self.find_beer(beer_hash) == nil self.new(beer_hash) else self.find_beer(beer_hash) end end end |