class ParamsReady::Value::RangeConstraint
Public Class Methods
new(cond, *args, **opts)
click to toggle source
Calls superclass method
ParamsReady::Value::Constraint::new
# File lib/params_ready/value/constraint.rb, line 59 def initialize(cond, *args, **opts) raise ParamsReadyError, "Expected Range, got: " + cond.class.name unless cond.is_a?(Range) super cond, *args, **opts end
Public Instance Methods
clamp(value)
click to toggle source
# File lib/params_ready/value/constraint.rb, line 72 def clamp(value) if value < @condition.min @condition.min elsif value > @condition.max @condition.max else value end end
clamp?()
click to toggle source
# File lib/params_ready/value/constraint.rb, line 82 def clamp? return false if @condition.min.nil? || @condition.max.nil? true end
error_message()
click to toggle source
# File lib/params_ready/value/constraint.rb, line 68 def error_message 'not in range' end
valid?(input)
click to toggle source
# File lib/params_ready/value/constraint.rb, line 64 def valid?(input) @condition.include?(input) end