mirror of
https://github.com/iritmaximus/brewery.git
synced 2026-10-12 19:13:49 +03:00
week 2 up to 4
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
class Beer < ApplicationRecord
|
||||
belongs_to :brewery
|
||||
has_many :ratings
|
||||
|
||||
def average_rating
|
||||
average = 0
|
||||
self.ratings.each do |rating|
|
||||
average += rating.score
|
||||
end
|
||||
return average
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
class Brewery < ApplicationRecord
|
||||
has_many :beers
|
||||
|
||||
def print_report
|
||||
puts name
|
||||
puts "established at year #{year}"
|
||||
puts "number of beers #{beers.count}"
|
||||
end
|
||||
|
||||
def restart
|
||||
self.year = 2023
|
||||
puts "changed year to #{2023}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class Rating < ApplicationRecord
|
||||
belongs_to :beer
|
||||
|
||||
def to_s
|
||||
"tekstiesitys"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user