diff --git a/app/models/item.rb b/app/models/item.rb index 52e621a4..11cf774e 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -195,6 +195,26 @@ class Item < ApplicationRecord nc_mall_record.present? end + def dyeworks? + dyeworks_base_item.present? + end + + DYEWORKS_NAME_PATTERN = %r{ + ^( + # Most Dyeworks items have a colon in the name. + Dyeworks\s+(?.+?:)\s*(?.+) + | + # But sometimes they omit it. If so, assume the first word is the color! + Dyeworks\s+(?\S+)\s*(?.+) + )$ + }x + def dyeworks_base_item + name_match = name.match(DYEWORKS_NAME_PATTERN) + return nil if name_match.nil? + + Item.find_by_name(name_match["base"]) + end + def owned? @owned || false end