Class: JSON::Schema::DivisibleByAttribute
- Defined in:
- lib/json-schema/attributes/divisibleby.rb
Direct Known Subclasses
Constant Summary
Constants inherited from Attribute
Attribute::TYPE_CLASS_MAPPINGS
Class Method Summary collapse
- .keyword ⇒ Object
- .validate(current_schema, data, fragments, processor, validator, options = {}) ⇒ Object
Methods inherited from Attribute
build_fragment, data_valid_for_type?, type_of_data, validation_error, validation_errors
Class Method Details
.keyword ⇒ Object
6 7 8 |
# File 'lib/json-schema/attributes/divisibleby.rb', line 6 def self.keyword 'divisibleBy' end |
.validate(current_schema, data, fragments, processor, validator, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/json-schema/attributes/divisibleby.rb', line 10 def self.validate(current_schema, data, fragments, processor, validator, = {}) return unless data.is_a?(Numeric) factor = current_schema.schema[keyword] if factor == 0 || factor == 0.0 || (BigDecimal(data.to_s) % BigDecimal(factor.to_s)).to_f != 0 = "The property '#{build_fragment(fragments)}' was not divisible by #{factor}" validation_error(processor, , fragments, current_schema, self, [:record_errors]) end end |