Class: ParamsChecker::ParamChecker::NumParamChecker

Inherits:
BaseParamChecker show all
Includes:
SimpleCommand
Defined in:
lib/params_checker/param_checker.rb

Instance Attribute Summary

Attributes inherited from BaseParamChecker

#fields, #key, #opts

Instance Method Summary collapse

Methods inherited from BaseParamChecker

#add_error, #initialize

Constructor Details

This class inherits a constructor from ParamsChecker::ParamChecker::BaseParamChecker

Instance Method Details

#callObject



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_paramObject



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_typeObject



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