Class: SimpleJSONSchema::Validators::Number

Inherits:
Numeric
  • Object
show all
Defined in:
lib/simple_json_schema/validators/number.rb

Constant Summary collapse

FLOAT_FORMAT =
/\A-?\d+\.\d+\Z/.freeze

Instance Method Summary collapse

Methods inherited from Base

#valid

Instance Method Details

#casting(value) ⇒ Object



16
17
18
# File 'lib/simple_json_schema/validators/number.rb', line 16

def casting(value)
  BigDecimal(value) if value.is_a?(::String) && FLOAT_FORMAT.match?(value)
end

#validate(scope) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/simple_json_schema/validators/number.rb', line 8

def validate(scope)
  value = scope.value

  return scope.error(:number) unless value.is_a?(::Numeric)

  super
end