Sha256: 7f7cacb356ae49c369bd3a9b32aa98180c9ac374e5e41b3cb32fb8a218d6b1a0
Contents?: true
Size: 902 Bytes
Versions: 2
Compression:
Stored size: 902 Bytes
Contents
module JsonTestData class String class << self def create(schema) return schema.fetch(:enum).sample if schema.fetch(:enum, nil) pattern(schema).random_example end private def pattern(schema) if schema.fetch(:format, nil) Regexp.new(formats.fetch(schema.fetch(:format))) elsif schema.fetch(:pattern, nil) Regexp.new(schema.fetch(:pattern)) else len = schema.fetch(:maxLength, nil) || schema.fetch(:minLength, nil) || 1 /.{#{len}}/ end end def formats { "date-time" => /^\d{4}(\-\d{2}){2}T\d{2}\:\d{2}\:\d{2}(Z|[\+\-]\d{2}\:\d{2})$/, "email" => /^\S+@\S+\.\S{1,5}$/, "hostname" => /^[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9]$/, "uri" => /^https?\:\/\/\S{1,10}\.\S{1,10}\.\S{2,5}$/ } end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
json_test_data-1.0.0 | lib/json_test_data/data_structures/string.rb |
json_test_data-0.9.0 | lib/json_test_data/data_structures/string.rb |