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
31 32 33 34 |
# File 'lib/beer_advocate/beer.rb', line 31 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.
6 7 8 |
# File 'lib/beer_advocate/beer.rb', line 6 def abv @abv end |
#brewery ⇒ Object
Returns the value of attribute brewery.
6 7 8 |
# File 'lib/beer_advocate/beer.rb', line 6 def brewery @brewery end |
#brewery_url ⇒ Object
Returns the value of attribute brewery_url.
6 7 8 |
# File 'lib/beer_advocate/beer.rb', line 6 def brewery_url @brewery_url end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/beer_advocate/beer.rb', line 6 def name @name end |
#name_url ⇒ Object
Returns the value of attribute name_url.
6 7 8 |
# File 'lib/beer_advocate/beer.rb', line 6 def name_url @name_url end |
#review_count ⇒ Object
Returns the value of attribute review_count.
6 7 8 |
# File 'lib/beer_advocate/beer.rb', line 6 def review_count @review_count end |
#score ⇒ Object
Returns the value of attribute score.
6 7 8 |
# File 'lib/beer_advocate/beer.rb', line 6 def score @score end |
#style ⇒ Object
Returns the value of attribute style.
6 7 8 |
# File 'lib/beer_advocate/beer.rb', line 6 def style @style end |
#style_url ⇒ Object
Returns the value of attribute style_url.
6 7 8 |
# File 'lib/beer_advocate/beer.rb', line 6 def style_url @style_url end |
Class Method Details
.all ⇒ Object
42 43 44 |
# File 'lib/beer_advocate/beer.rb', line 42 def self.all @@all end |
.create_from_collection(beers_array) ⇒ Object
36 37 38 39 40 |
# File 'lib/beer_advocate/beer.rb', line 36 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
46 47 48 |
# File 'lib/beer_advocate/beer.rb', line 46 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
50 51 52 53 54 55 56 57 58 |
# File 'lib/beer_advocate/beer.rb', line 50 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 |