Oops, fix pb_item for "Royal Girl Elephante Gold Bracelets" and similar

There's some funny bugs we had here, like "Relic Elephante Jewellery"
and "Royal Girl Skeith Bodice" getting assigned "Ice", and
"Tyrannian Meerca Spear" being "Pea" lmao

I went and checked all the assignments now and they look good to me!

```ruby
Item.is_pb.order(:name).
  map { |i| [i.pb_color&.human_name, i.name] }
```
This commit is contained in:
Emi Matchu 2024-09-13 19:56:41 -07:00
parent fdf1f31867
commit 989c96fd2b

View file

@ -243,8 +243,14 @@ class Item < ApplicationRecord
normalized_name = name.downcase.gsub("female", "girl").gsub("male", "boy"). normalized_name = name.downcase.gsub("female", "girl").gsub("male", "boy").
gsub(/\s/, "") gsub(/\s/, "")
Color.order(:name). # For each color, normalize its name, look for it in the item name, and
find { |c| normalized_name.include?(c.name.downcase.gsub(/\s/, "")) } # return the matching color that appears earliest. (This is important for
# items that contain multiple color names, like the "Royal Girl Elephante
# Gold Bracelets".)
Color.all.to_h { |c| [c, c.name.downcase.gsub(/\s/, "")] }.
transform_values { |n| normalized_name.index(n) }.
filter { |c, n| n.present? }.
min_by { |c, i| i }&.first
end end
# If this is a PB item, return the corresponding Species, inferred from the # If this is a PB item, return the corresponding Species, inferred from the