Class: JSON::Schema::TimeFormat
- Inherits:
-
FormatAttribute
- Object
- Attribute
- FormatAttribute
- JSON::Schema::TimeFormat
- Defined in:
- lib/json-schema/attributes/formats/time.rb
Constant Summary collapse
- REGEXP =
/\A(\d{2}):(\d{2}):(\d{2})\z/
Constants inherited from Attribute
Attribute::TYPE_CLASS_MAPPINGS
Class Method Summary collapse
Methods inherited from Attribute
build_fragment, data_valid_for_type?, type_of_data, validation_error, validation_errors
Class Method Details
.validate(current_schema, data, fragments, processor, validator, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/json-schema/attributes/formats/time.rb', line 8 def self.validate(current_schema, data, fragments, processor, validator, = {}) if data.is_a?(String) = "The property '#{build_fragment(fragments)}' must be a time in the format of hh:mm:ss" if (m = REGEXP.match(data)) validation_error(processor, , fragments, current_schema, self, [:record_errors]) and return if m[1].to_i > 23 validation_error(processor, , fragments, current_schema, self, [:record_errors]) and return if m[2].to_i > 59 validation_error(processor, , fragments, current_schema, self, [:record_errors]) and return if m[3].to_i > 59 else validation_error(processor, , fragments, current_schema, self, [:record_errors]) end end end |