From 68cb44d159b47fe35a86bebbcd2146c46f1903b1 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Fri, 7 Jun 2024 19:20:21 -0700 Subject: [PATCH] Add logic to infer the base for Dyeworks items This works for most of the current 1,094 Dyeworks items! But there are a few exceptions, for cases where the base item name is not quite the same (e.g. the Dyeworks version is more concise). Maybe we'll add a database field to override this? - Dyeworks Baby Blue: Baby Valentine Jumper - Dyeworks Baby Pink: Baby Valentine Jumper - Dyeworks Black: Field of Flowers - Dyeworks Black: Games Master Challenge 2010 Lulu Shirt - Dyeworks Blue: Field of Flowers - Dyeworks Blue: Stars and Glitter Facepaint - Dyeworks Brown: Hanging Winter Candles Garland - Dyeworks Green: Stars and Glitter Facepaint - Dyeworks Magenta: Lovely Berry Blush - Dyeworks Orange & Pink: Winter Lights Effects - Dyeworks Orange: Games Master Challenge 2010 Lulu Shirt - Dyeworks Peach: Lovely Berry Blush - Dyeworks Purple: Baby Valentine Jumper - Dyeworks Purple: Games Master Challenge 2010 Lulu Shirt - Dyeworks Purple: Hanging Winter Candles Garland - Dyeworks Purple: Stars and Glitter Facepaint - Dyeworks Red & Green: Winter Lights Effects - Dyeworks Silver: Hanging Winter Candles Garland - Dyeworks Soft Pink: Lovely Berry Blush - Dyeworks Yellow & Magenta: Winter Lights Effects - Dyeworks Yellow: Field of Flowers --- app/models/item.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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