Improve Owls value presentation in Item Getting Guide

This commit is contained in:
Emi Matchu 2024-06-09 19:22:34 -07:00
parent be525d1d67
commit 3310394fb8
3 changed files with 61 additions and 11 deletions

View file

@ -85,10 +85,11 @@
color: inherit
.owls-info-link
cursor: help
.owls-info-label
text-decoration-line: underline
text-decoration-style: dotted
cursor: help
/* For wearable items that belong to a specific set that all come together,
* like a Paint Brush. */

View file

@ -156,6 +156,39 @@ module ItemsHelper
"Last updated: #{date_str} (#{time_ago_str} ago)"
end
NC_TRADE_VALUE_ESTIMATE_PATTERN = %r{
^\s*
(?:
# Case 1: A single number
(?<single>[0-9]+)
|
# Case 2: A range from low to high
(?<low>[0-9]+)
\p{Dash_Punctuation}
(?<high>[0-9]+)
)
\s*$
}x
def nc_trade_value_is_estimate(nc_trade_value)
nc_trade_value.value_text.match?(NC_TRADE_VALUE_ESTIMATE_PATTERN)
end
# Try to parse the NC trade value's text into something styled a bit more
# nicely for our use case.
def nc_trade_value_estimate_text(nc_trade_value)
match = nc_trade_value.value_text.match(NC_TRADE_VALUE_ESTIMATE_PATTERN)
return nc_trade_value if match.nil?
match => {single:, low:, high:}
if single.present?
pluralize single.to_i, "capsule"
elsif low.present? && high.present?
"#{low}#{high} capsules"
else
nc_trade_value
end
end
def nc_total_for(items)
items.map(&:current_nc_price).sum
end

View file

@ -156,14 +156,21 @@
- if @other_nc_items.present?
%h2 Neocash items (Capsules, events, retired, etc.)
:markdown
These items are part of the Neocash economy and can't be purchased with
Neopoints. We don't track all the details of how to get these items
right now! Sometimes they're available via packs or capsules or events
in the [NC Mall][mall]. Sometimes they're retired and can't be
purchased at all anymore, and can only be obtained via gifts or trades.
These items are part of the Neocash economy, but not directly for sale.
Sometimes they're available in the [NC Mall][mall], via special
bundles or events. Sometimes they're retired, and can only be obtained via
gifts or trades.
[mall]: https://ncmall.neopets.com/
- if @other_nc_items.any?(&:nc_trade_value)
:markdown
The [Owls Value Guide][owls] often has more details about how to get
these items, and how much they're usually worth in the NC Trading
community. We've loaded their info here for you, too! Thanks, Owls team!
[owls]: https://www.neopets.com/~owls
%table.item-list
%thead
%td
@ -174,10 +181,19 @@
= render "item_list_row", item: do
- content_for :subtitle, flush: true do
- if item.nc_trade_value.present?
- if nc_trade_value_is_estimate(item.nc_trade_value)
= link_to "https://www.neopets.com/~owls",
class: "owls-info-link", target: "_blank",
title: 'Owls keeps track of approximate "capsule" values of NC items for trading. Items with similar values can often be traded for one another. This is an estimate, not a rule!' do
%span.owls-info-label Owls listing:
%span.owls-info-label [Owls]
Estimated value:
= nc_trade_value_estimate_text(item.nc_trade_value)
- else
= link_to "https://www.neopets.com/~owls",
class: "owls-info-link", target: "_blank",
title: "Owls keeps track of how to get certain special items, even when there isn't a clear NC trade estimate." do
%span.owls-info-label [Owls]
Trade info:
#{item.nc_trade_value.value_text}
= button_link_to "NC Trades",