Class: ParamsReady::Value::OperatorConstraint

Inherits:
Constraint
  • Object
show all
Defined in:
lib/params_ready/value/constraint.rb

Defined Under Namespace

Modules: ClampingCondition Classes: Condition, DynamicCondition, StaticCondition

Constant Summary collapse

OPERATORS =
[:=~, :<, :<=, :==, :>=, :>].to_set.freeze

Instance Attribute Summary

Attributes inherited from Constraint

#condition

Instance Method Summary collapse

Methods inherited from Constraint

build, instance, register

Methods included from Extensions::Registry

#human_string, #registry

Constructor Details

#initialize(operator, value, *args, **opts) ⇒ OperatorConstraint

Returns a new instance of OperatorConstraint.



117
118
119
120
121
122
123
# File 'lib/params_ready/value/constraint.rb', line 117

def initialize(operator, value, *args, **opts)
  unless OPERATORS.member? operator
    raise ParamsReadyError, "Unsupported operator: #{operator}"
  end
  cond = Condition.instance(operator, value)
  super(cond, *args, **opts)
end

Instance Method Details

#clamp(value) ⇒ Object



125
126
127
128
129
# File 'lib/params_ready/value/constraint.rb', line 125

def clamp(value)
  return value if valid?(value)

  @condition.clamp(value)
end

#clamp?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/params_ready/value/constraint.rb', line 131

def clamp?
  @condition.clamp?
end

#error_messageObject



139
140
141
# File 'lib/params_ready/value/constraint.rb', line 139

def error_message
  @condition.error_message
end

#valid?(input) ⇒ Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/params_ready/value/constraint.rb', line 135

def valid?(input)
  @condition.true?(input)
end