mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 04:34:32 +08:00
21 lines
495 B
Ruby
21 lines
495 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
|