Class: ParamsChecker::ParamChecker::NumParamChecker
Instance Attribute Summary
#fields, #key, #opts
Instance Method Summary
collapse
#add_error, #initialize
Instance Method Details
#call ⇒ Object
22
23
24
25
26
27
|
# File 'lib/params_checker/param_checker.rb', line 22
def call
return nil if fields[key][:allow_nil] && opts[key].nil?
check_type && check_param
opts[key]
end
|
#check_param ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/params_checker/param_checker.rb', line 35
def check_param
min = fields[key][:min]
max = fields[key][:max]
valid =(min..max).include? opts[key]
add_error("This numeric field's value must be in range from #{min} to #{max}.") unless valid
valid
end
|
#check_type ⇒ Object
29
30
31
32
33
|
# File 'lib/params_checker/param_checker.rb', line 29
def check_type
valid = opts[key].is_a? Numeric
add_error("This field's type must be numeric.") unless valid
valid
end
|