week 2 up to 4

This commit is contained in:
iritmaximus
2023-06-13 13:08:42 +03:00
parent 34646c6dad
commit fdb6de1f4a
12 changed files with 93 additions and 1 deletions
+9
View File
@@ -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
+11
View File
@@ -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
+7
View File
@@ -0,0 +1,7 @@
class Rating < ApplicationRecord
belongs_to :beer
def to_s
"tekstiesitys"
end
end