module HasCostsAndRequirements extend ActiveSupport::Concern included do def costs costs = [] self.whatnot[:cost]&.each do |cost| case cost[:type] when "item" costs.push "#{cost[:quantity]} #{Item.find_by_gid(cost[:gid]).name}" end end costs end def requirements requirements = [] self.whatnot[:requirements]&.each do |req| case req[:type] when "skill" requirements.push "level #{req[:level]} #{Skill.find_by_gid(req[:gid]).name}" when "stat" requirements.push "#{req[:value]} #{req[:gid]}" when "equipment" if req[:tag] requirements.push "equipped #{req[:tag]}" else requirements.push "equipped #{Item.find_by_gid(req[:gid]).name}" end when "hearth_amenity" requirements.push "level #{req[:level]} #{HearthAmenity.find_by_gid(req[:gid]).name}" when "time_of_day" requirements.push "a certain time of day (#{req[:times].join(", ")})" else raise "Invalid requirement type string (#{req[:type]})" end end requirements end end end