Created
March 31, 2017 04:32
-
-
Save coffeejunk/9f0a6edc85ca8dc83d586fad44c5fed3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json-schema' | |
require 'json' | |
schema = JSON.parse( | |
<<JSONSCHEMA | |
{ | |
"type": "object", | |
"required": [ | |
"ceterms:foundingDate" | |
], | |
"properties": { | |
"ceterms:foundingDate": { | |
"anyOf": [ | |
{ | |
"type": "string", | |
"format": "date" | |
}, | |
{ | |
"type": "string", | |
"format": "date-time" | |
} | |
] | |
} | |
} | |
} | |
JSONSCHEMA | |
) | |
puts schema.to_json | |
%w{ | |
2017 | |
2017-03 | |
2017-03-31 | |
2017-03-31T01:37:59Z | |
20170331T013759Z | |
2017-03-31T01:37:59+00:00 | |
}.each do |date| | |
data = { 'ceterms:foundingDate' => date } | |
print data.to_json | |
print ' valid? ' | |
puts JSON::Validator.validate(schema, data) | |
end |
Author
coffeejunk
commented
Mar 31, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment