Sha256: 74d85837e2b95f9ec8a29ab7c73ca39ad708d81fb188993c62be5dd9f6165827

Contents?: true

Size: 742 Bytes

Versions: 3

Compression:

Stored size: 742 Bytes

Contents

class OpenAPIParser::SchemaValidator
  class FloatValidator < Base
    include ::OpenAPIParser::SchemaValidator::Enumable

    def coerce_and_validate(value, schema)
      value = coerce(value) if @coerce_value

      return validator.validate_integer(value, schema) if value.is_a?(Integer)
      coercer_and_validate_numeric(value, schema)
    end

    private

    def coercer_and_validate_numeric(value, schema)
      return validator.validate_error(value, schema) unless value.is_a?(Numeric)
      check_enum_include(value, schema)
    end

    private

    def coerce(value)
      begin
        return Float(value)
      rescue ArgumentError => e
        raise e unless e.message =~ /invalid value for Float/
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
openapi_parser-0.1.5 lib/openapi_parser/schema_validators/float_validator.rb
openapi_parser-0.1.4 lib/openapi_parser/schema_validators/float_validator.rb
openapi_parser-0.1.3 lib/openapi_parser/schema_validators/float_validator.rb