Class: SimpleJSONSchema::Validators::Numeric

Inherits:
Base
  • Object
show all
Defined in:
lib/simple_json_schema/validators/numeric.rb

Direct Known Subclasses

Integer, Number

Instance Method Summary collapse

Methods inherited from Base

#valid

Instance Method Details

#validate(scope) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/simple_json_schema/validators/numeric.rb', line 6

def validate(scope)
  value = scope.value

  Checker.at_value(scope, :maximum, :>)
  Checker.at_value(scope, :minimum, :<)
  Checker.at_value(scope, :exclusiveMaximum, :>=)
  Checker.at_value(scope, :exclusiveMinimum, :<=)

  multiple_of = scope[:multipleOf]
  return unless multiple_of

  quotient = value / multiple_of.to_f
  scope.error(:multipleOf) unless quotient.floor == quotient
end