class Hearth < ApplicationRecord belongs_to :character has_many :built_hearth_amenities has_many :hearth_amenities, through: :built_hearth_amenities def has_amenity?(hearth_amenity, level = 1) hearth_amenity = HearthAmenity.find_by_gid(hearth_amenity) if hearth_amenity.is_a? String bhi = self.built_hearth_amenities.find_by(hearth_amenity: hearth_amenity) return false unless bhi bhi.level >= level end def amenity_level(hearth_amenity) hearth_amenity = HearthAmenity.find_by_gid(hearth_amenity) if hearth_amenity.is_a? String bhi = self.built_hearth_amenities.find_by(hearth_amenity: hearth_amenity) bhi ? bhi.level : 0 end end