diff options
author | David Gay <david@davidgay.org> | 2021-05-27 17:27:42 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-05-27 17:27:42 -0400 |
commit | 82ebb73bb4fc53ec5af428a88809ab8f11e52c0b (patch) | |
tree | aa1e85e2bdb4a772317f89dc8f56db42df92d6d9 /app/models | |
parent | 25b01cb1df594d0b80adf719ef1cb5dbe9c62ab5 (diff) |
Display cost and requirements of any activity that fails to start
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/activity.rb | 23 |
1 files changed, 19 insertions, 4 deletions
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 |