From 82ebb73bb4fc53ec5af428a88809ab8f11e52c0b Mon Sep 17 00:00:00 2001 From: David Gay Date: Thu, 27 May 2021 17:27:42 -0400 Subject: Display cost and requirements of any activity that fails to start --- app/models/activity.rb | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'app/models') diff --git a/app/models/activity.rb b/app/models/activity.rb index 7272a3b..562abf4 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -6,14 +6,29 @@ class Activity < ApplicationRecord attribute :innate, :boolean, default: false - def cost_string - requirements = [] + def costs + costs = [] self.whatnot[:cost].each do |cost| case cost[:type] when "item" - requirements.push "#{cost[:quantity]} #{Item.find_by_gid(cost[:gid]).name}" + 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 "hearth_amenity" + requirements.push "level #{req[:level]} #{HearthAmenity.find_by_gid(req[:gid]).name}" + else + raise "Invalid requirement type string (#{req[:type]})" end end - requirements.join(", ") + requirements end end -- cgit v1.2.3