Class: CategorySearchPriorityWeightsValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/validators/category_search_priority_weights_validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ CategorySearchPriorityWeightsValidator

Returns a new instance of CategorySearchPriorityWeightsValidator.



4
5
6
# File 'lib/validators/category_search_priority_weights_validator.rb', line 4

def initialize(opts = {})
  @name = opts[:name].to_s
end

Instance Method Details

#error_messageObject



19
20
21
22
# File 'lib/validators/category_search_priority_weights_validator.rb', line 19

def error_message
  key = @name[/category_search_priority_(\w+)_weight/, 1]
  I18n.t("site_settings.errors.category_search_priority.#{key}_weight_invalid")
end

#valid_value?(val) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
# File 'lib/validators/category_search_priority_weights_validator.rb', line 8

def valid_value?(val)
  val = val.to_f

  case @name
  when "category_search_priority_low_weight"
    val < 1
  when "category_search_priority_high_weight"
    val > 1
  end
end