Class: ParamsChecker::ParamChecker::IntParamChecker

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



47
48
49
50
51
52
# File 'lib/params_checker/param_checker.rb', line 47

def call
      return nil if fields[key][:allow_nil] && opts[key].nil?

    check_type && check_param
    opts[key]
end

#check_paramObject



60
61
62
63
64
65
66
# File 'lib/params_checker/param_checker.rb', line 60

def check_param
    min = fields[key][:min]
    max = fields[key][:max]
    valid = (min..max).include? opts[key]
    add_error("This integer field's value must be in range from #{min} to #{max}.") unless valid
    valid
end

#check_typeObject



54
55
56
57
58
# File 'lib/params_checker/param_checker.rb', line 54

def check_type
    valid = opts[key].is_a? Integer
    add_error("This field's type must be integer.") unless valid
    valid
end