forked from OpenNeo/impress
Improve parsing fits:blue-acara
filter
Previously, passing in `fits:blue` would cause a crash, because `species_name` part of the split would be `nil`, oops! In this change, we use a regex for more explicitness about the pattern we're trying to match. We'll also add more cases next! (You'll note the error message mentions `fits:nostalgic-faerie-draik`, which isn't actually possible yet, but will be!)
This commit is contained in:
parent
1860f5b6be
commit
61b1a1aed1
2 changed files with 13 additions and 5 deletions
|
@ -62,11 +62,17 @@ class Item
|
||||||
when 'restricts'
|
when 'restricts'
|
||||||
is_positive ? Filter.restricts(value) : Filter.not_restricts(value)
|
is_positive ? Filter.restricts(value) : Filter.not_restricts(value)
|
||||||
when 'fits'
|
when 'fits'
|
||||||
color_name, species_name = value.split("-")
|
match = value.match(/^([^-]+)-([^-]+)$/)
|
||||||
|
if match.present?
|
||||||
|
color_name, species_name = match.captures
|
||||||
pet_type = load_pet_type_by_name(color_name, species_name)
|
pet_type = load_pet_type_by_name(color_name, species_name)
|
||||||
is_positive ?
|
return is_positive ?
|
||||||
Filter.fits_pet_type(pet_type, color_name:, species_name:) :
|
Filter.fits_pet_type(pet_type, color_name:, species_name:) :
|
||||||
Filter.not_fits_pet_type(pet_type, color_name:, species_name:)
|
Filter.not_fits_pet_type(pet_type, color_name:, species_name:)
|
||||||
|
end
|
||||||
|
message = I18n.translate('items.search.errors.not_found.fits_target',
|
||||||
|
value: value)
|
||||||
|
raise Item::Search::Error, message
|
||||||
when 'species'
|
when 'species'
|
||||||
begin
|
begin
|
||||||
species = Species.find_by_name!(value)
|
species = Species.find_by_name!(value)
|
||||||
|
|
|
@ -361,6 +361,8 @@ en:
|
||||||
alt_style: We have no record of the "%{filter_text}" alt style. Is it
|
alt_style: We have no record of the "%{filter_text}" alt style. Is it
|
||||||
spelled correctly?
|
spelled correctly?
|
||||||
pet_type_id: We have no record of pet type %{id}. Weird.
|
pet_type_id: We have no record of pet type %{id}. Weird.
|
||||||
|
fits_target: I'm not sure what "fits:%{value}" means. You can
|
||||||
|
use "fits:blue-acara", "fits:nostalgic-faerie-draik", or similar!
|
||||||
not_logged_in: The "user" filters are only available if you're logged in.
|
not_logged_in: The "user" filters are only available if you're logged in.
|
||||||
flag_keywords:
|
flag_keywords:
|
||||||
is: is
|
is: is
|
||||||
|
|
Loading…
Reference in a new issue