discourse/lib/validators/search_ranking_weights_vali...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

21 lines
495 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class SearchRankingWeightsValidator
def initialize(opts = {})
@opts = opts
end
WEIGHT_REGEXP = "1\.0|0\.[0-9]+"
2023-02-02 07:24:42 -05:00
WEIGHTS_REGEXP =
/{(?<d_weight>#{WEIGHT_REGEXP}),(?<c_weight>#{WEIGHT_REGEXP}),(?<b_weight>#{WEIGHT_REGEXP}),(?<a_weight>#{WEIGHT_REGEXP})}/
def valid_value?(value)
return true if value.blank?
value.match(WEIGHTS_REGEXP)
end
def error_message
I18n.t("site_settings.errors.invalid_search_ranking_weights")
end
end