mirror of
https://github.com/iritmaximus/brewery.git
synced 2026-10-12 19:13:49 +03:00
removed rubocop warning with cool syntastic sugar :D
This commit is contained in:
@@ -7,7 +7,7 @@ module RatingAverage
|
|||||||
elsif instance_of?(Brewery)
|
elsif instance_of?(Brewery)
|
||||||
# creates empty arrays for beers that have no ratings
|
# creates empty arrays for beers that have no ratings
|
||||||
# + wraps the array in an array
|
# + wraps the array in an array
|
||||||
ratings = beers.map { |b| b.ratings }.reject(&:blank?)[0]
|
ratings = beers.map(&:b.ratings).reject(&:blank?)[0]
|
||||||
elsif instance_of?(User)
|
elsif instance_of?(User)
|
||||||
ratings = self.ratings
|
ratings = self.ratings
|
||||||
else
|
else
|
||||||
@@ -16,14 +16,14 @@ module RatingAverage
|
|||||||
|
|
||||||
return 0 unless ratings.count > 0
|
return 0 unless ratings.count > 0
|
||||||
|
|
||||||
ratings.map { |r| r.score }.sum / ratings.count.to_f
|
ratings.map(&:r.score).sum / ratings.count.to_f
|
||||||
end
|
end
|
||||||
|
|
||||||
def count_ratings
|
def count_ratings
|
||||||
if instance_of?(Beer) || User
|
if instance_of?(Beer) || User
|
||||||
ratings.count
|
ratings.count
|
||||||
elsif instance_of?(Brewery)
|
elsif instance_of?(Brewery)
|
||||||
beers.map { |b| b.ratings.count }.sum
|
beers.map(&:ratings.count).sum
|
||||||
else
|
else
|
||||||
raise "Wrong class type for counting ratings, #{self.class}"
|
raise "Wrong class type for counting ratings, #{self.class}"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user