discourse/lib/validators/search_ranking_weights_validator.rb
2023-02-01 06:43:41 +08:00

20 lines
491 B
Ruby

# frozen_string_literal: true
class SearchRankingWeightsValidator
def initialize(opts = {})
@opts = opts
end
WEIGHT_REGEXP = "1\.0|0\.[0-9]+"
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