Sha256: 2b15b837d7ae11e03acbeb89b73343a2dc518e088c0dbe6eca994431df4e1da7

Contents?: true

Size: 1.01 KB

Versions: 15

Compression:

Stored size: 1.01 KB

Contents

require 'json-schema/attributes/format'

module JSON
  class Schema
    class TimeFormat < FormatAttribute
      REGEXP = /\A(\d{2}):(\d{2}):(\d{2})\z/

      def self.validate(current_schema, data, fragments, processor, validator, options = {})
        if data.is_a?(String)
          error_message = "The property '#{build_fragment(fragments)}' must be a time in the format of hh:mm:ss"
          if (m = REGEXP.match(data))
            validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors]) and return if m[1].to_i > 23
            validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors]) and return if m[2].to_i > 59
            validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors]) and return if m[3].to_i > 59
          else
            validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors])
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 14 versions & 3 rubygems

Version Path
json-schema-5.1.0 lib/json-schema/attributes/formats/time.rb
json-schema-ouidou-2.9.1 lib/json-schema/attributes/formats/time.rb
json-schema-ouidou-2.9.0 lib/json-schema/attributes/formats/time.rb
json-schema-5.0.1 lib/json-schema/attributes/formats/time.rb
json-schema-5.0.0 lib/json-schema/attributes/formats/time.rb
json-schema-4.3.1 lib/json-schema/attributes/formats/time.rb
json-schema-4.3.0 lib/json-schema/attributes/formats/time.rb
json-schema-4.2.0 lib/json-schema/attributes/formats/time.rb
json-schema-4.1.1 lib/json-schema/attributes/formats/time.rb
json-schema-4.1.0 lib/json-schema/attributes/formats/time.rb
json-schema-4.0.0 lib/json-schema/attributes/formats/time.rb
json-schema-3.0.0 lib/json-schema/attributes/formats/time.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/bundler/gems/json-schema-2253a5ee6679/lib/json-schema/attributes/formats/time.rb
mountapi-0.11.1 vendor/json-schema/lib/json-schema/attributes/formats/time.rb
json-schema-2.8.1 lib/json-schema/attributes/formats/time.rb