Class: Cl::Opts::Validate::Range

Inherits:
Validator
  • Object
show all
Defined in:
lib/cl/opts/validate.rb

Instance Attribute Summary

Attributes inherited from Validator

#cmd, #opts, #orig, #values

Instance Method Summary collapse

Methods inherited from Validator

#compact, #invert, #only

Methods included from Regex

#format_regex

Instance Method Details

#applyObject

Raises:



98
99
100
# File 'lib/cl/opts/validate.rb', line 98

def apply
  raise OutOfRange.new(invalid) if invalid.any?
end

#invalidObject



102
103
104
105
106
107
108
# File 'lib/cl/opts/validate.rb', line 102

def invalid
  @invalid ||= opts.map do |opt|
    next unless value = values[opt.name]
    range = only(opt.opts, :min, :max)
    [opt.name, compact(range)] if invalid?(range, value)
  end.compact
end

#invalid?(range, value) ⇒ Boolean

Returns:

  • (Boolean)


110
111
112
113
# File 'lib/cl/opts/validate.rb', line 110

def invalid?(range, value)
  min, max = range.values_at(:min, :max)
  min && value < min || max && value > max
end