Sha256: 954e405e56c55383eb996ebe691dae2b5588e4c907ae0509f72ef23205f33c70

Contents?: true

Size: 638 Bytes

Versions: 3

Compression:

Stored size: 638 Bytes

Contents

require 'json-schema/attribute'

module JSON
  class Schema
    class MaxDecimalAttribute < Attribute
      def self.validate(current_schema, data, fragments, processor, validator, options = {})
        if data.is_a?(Numeric)
          s = data.to_s.split(".")[1]
          if s && s.length > current_schema.schema['maxDecimal']
            message = "The property '#{build_fragment(fragments)}' had more decimal places than the allowed #{current_schema.schema['maxDecimal']}"
            validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
json-schema-2.4.1 lib/json-schema/attributes/maxdecimal.rb
json-schema-2.4.0 lib/json-schema/attributes/maxdecimal.rb
json-schema-2.3.0 lib/json-schema/attributes/maxdecimal.rb