Oops, fix indentation in Item::Dyeworks

Ahh, I started a tabs-y file (as I default to these days), but copied
code from a spaces-y file, and didn't notice. (My laptop editor isn't
configured to flag this for me, oops!)

Fixed!
This commit is contained in:
Emi Matchu 2024-06-18 16:50:43 -07:00
parent 10301900e2
commit b6bd539fed

View file

@ -1,106 +1,106 @@
class Item class Item
module Dyeworks module Dyeworks
def dyeworks? def dyeworks?
dyeworks_base_item.present? dyeworks_base_item.present?
end end
# Whether this is a Dyeworks item whose base item can currently be purchased # Whether this is a Dyeworks item whose base item can currently be purchased
# in the NC Mall, then dyed via Dyeworks. (Owls tracks this last part!) # in the NC Mall, then dyed via Dyeworks. (Owls tracks this last part!)
def dyeworks_buyable? def dyeworks_buyable?
dyeworks_base_buyable? && dyeworks_dyeable? dyeworks_base_buyable? && dyeworks_dyeable?
end end
# Whether this is a Dyeworks item whose base item can currently be purchased # Whether this is a Dyeworks item whose base item can currently be purchased
# in the NC Mall. It may or may not currently be *dyeable* in the NC Mall, # in the NC Mall. It may or may not currently be *dyeable* in the NC Mall,
# because Dyeworks eligibility is often a limited-time event. # because Dyeworks eligibility is often a limited-time event.
def dyeworks_base_buyable? def dyeworks_base_buyable?
dyeworks_base_item.present? && dyeworks_base_item.currently_in_mall? dyeworks_base_item.present? && dyeworks_base_item.currently_in_mall?
end end
# Whether this is a Dyeworks item that can be dyed in the NC Mall ~right now, # Whether this is a Dyeworks item that can be dyed in the NC Mall ~right now,
# either at any time or as a limited-time event. (Owls tracks this, not us!) # either at any time or as a limited-time event. (Owls tracks this, not us!)
def dyeworks_dyeable? def dyeworks_dyeable?
dyeworks_permanent? || dyeworks_limited_active? dyeworks_permanent? || dyeworks_limited_active?
end end
# Whether this is one of the few Dyeworks items that can be dyed in the NC # Whether this is one of the few Dyeworks items that can be dyed in the NC
# Mall at any time, rather than as part of a limited-time event. (Owls tracks # Mall at any time, rather than as part of a limited-time event. (Owls tracks
# this, not us!) # this, not us!)
DYEWORKS_PERMANENT_PATTERN = /Permanent\s*Dyeworks/i DYEWORKS_PERMANENT_PATTERN = /Permanent\s*Dyeworks/i
def dyeworks_permanent? def dyeworks_permanent?
return false if nc_trade_value.nil? return false if nc_trade_value.nil?
nc_trade_value.value_text.match?(DYEWORKS_PERMANENT_PATTERN) nc_trade_value.value_text.match?(DYEWORKS_PERMANENT_PATTERN)
end end
# Whether this is a Dyeworks item that can be dyed in the NC Mall ~right # Whether this is a Dyeworks item that can be dyed in the NC Mall ~right
# now, as part of a limited-time event. (Owls tracks this, not us!) # now, as part of a limited-time event. (Owls tracks this, not us!)
# #
# If we aren't sure of the final date, this will still return `true`, on # If we aren't sure of the final date, this will still return `true`, on
# the assumption it *is* dyeable right now and we just don't understand the # the assumption it *is* dyeable right now and we just don't understand the
# details of what Owls told us. # details of what Owls told us.
def dyeworks_limited_active? def dyeworks_limited_active?
return false unless dyeworks_limited? return false unless dyeworks_limited?
return true if dyeworks_limited_final_date.nil? return true if dyeworks_limited_final_date.nil?
# NOTE: The application is configured to NST, so this should be # NOTE: The application is configured to NST, so this should be
# equivalent to `Date.today`, but this is clearer and more correct imo! # equivalent to `Date.today`, but this is clearer and more correct imo!
today_in_nst = Time.find_zone("Pacific Time (US & Canada)").today today_in_nst = Time.find_zone("Pacific Time (US & Canada)").today
today_in_nst <= dyeworks_limited_final_date today_in_nst <= dyeworks_limited_final_date
end end
# Whether this is a Dyeworks item that can only be dyed as part of a # Whether this is a Dyeworks item that can only be dyed as part of a
# limited-time event. (This may return true even if the end date has # limited-time event. (This may return true even if the end date has
# passed, see `dyeworks_limited_active?`.) (Owls tracks this, not us!) # passed, see `dyeworks_limited_active?`.) (Owls tracks this, not us!)
DYEWORKS_LIMITED_PATTERN = /Limited\s*Dyeworks/i DYEWORKS_LIMITED_PATTERN = /Limited\s*Dyeworks/i
def dyeworks_limited? def dyeworks_limited?
return false if nc_trade_value.nil? return false if nc_trade_value.nil?
nc_trade_value.value_text.match?(DYEWORKS_LIMITED_PATTERN) nc_trade_value.value_text.match?(DYEWORKS_LIMITED_PATTERN)
end end
# If this is a limited-time Dyeworks item, this is the date we think the # If this is a limited-time Dyeworks item, this is the date we think the
# event will end on. Even if `dyeworks_limited?` returns true, this could # event will end on. Even if `dyeworks_limited?` returns true, this could
# still be `nil`, if we fail to parse this. (Owls tracks this, not us!) # still be `nil`, if we fail to parse this. (Owls tracks this, not us!)
DYEWORKS_LIMITED_FINAL_DATE_PATTERN = DYEWORKS_LIMITED_FINAL_DATE_PATTERN =
/Dyeable\s*Thru\s*(?<month>[a-z]+)\s*(?<day>[0-9]+)/i /Dyeable\s*Thru\s*(?<month>[a-z]+)\s*(?<day>[0-9]+)/i
def dyeworks_limited_final_date def dyeworks_limited_final_date
return nil unless dyeworks_limited? return nil unless dyeworks_limited?
match = nc_trade_value.value_text. match = nc_trade_value.value_text.
match(DYEWORKS_LIMITED_FINAL_DATE_PATTERN) match(DYEWORKS_LIMITED_FINAL_DATE_PATTERN)
return nil if match.nil? return nil if match.nil?
# Parse this "<Month> <Day>" date as the *next* such date: parse it as # Parse this "<Month> <Day>" date as the *next* such date: parse it as
# this year at first, then add a year if it turns out to be in the past. # this year at first, then add a year if it turns out to be in the past.
# #
# NOTE: This could return strange results if the Owls date contains # NOTE: This could return strange results if the Owls date contains
# something surprising! But the heuristic nature helps with e.g. # something surprising! But the heuristic nature helps with e.g.
# flexibility if they abbreviate months, so let's lean into `Date.parse`. # flexibility if they abbreviate months, so let's lean into `Date.parse`.
match => {month:, day:} match => {month:, day:}
date = Date.parse("#{month} #{day}, #{Date.today.year}") date = Date.parse("#{month} #{day}, #{Date.today.year}")
date += 1.year if date < Date.today date += 1.year if date < Date.today
date date
end end
# Infer what base item this Dyeworks item probably relates to, based on # Infer what base item this Dyeworks item probably relates to, based on
# their names. We only use this when a new item is modeled to initialize # their names. We only use this when a new item is modeled to initialize
# the `dyeworks_base_item` relationship in the database; after that, we # the `dyeworks_base_item` relationship in the database; after that, we
# just use whatever the database says. (This allows manual overrides!) # just use whatever the database says. (This allows manual overrides!)
DYEWORKS_NAME_PATTERN = %r{ DYEWORKS_NAME_PATTERN = %r{
^( ^(
# Most Dyeworks items have a colon in the name. # Most Dyeworks items have a colon in the name.
Dyeworks\s+(?<color>.+?:)\s*(?<base>.+) Dyeworks\s+(?<color>.+?:)\s*(?<base>.+)
| |
# But sometimes they omit it. If so, assume the first word is the color! # But sometimes they omit it. If so, assume the first word is the color!
Dyeworks\s+(?<color>\S+)\s*(?<base>.+) Dyeworks\s+(?<color>\S+)\s*(?<base>.+)
)$ )$
}x }x
def inferred_dyeworks_base_item def inferred_dyeworks_base_item
name_match = name.match(DYEWORKS_NAME_PATTERN) name_match = name.match(DYEWORKS_NAME_PATTERN)
return nil if name_match.nil? return nil if name_match.nil?
Item.find_by_name(name_match["base"]) Item.find_by_name(name_match["base"])
end end
end end
end end