Class: JSON::Schema::String
Overview
The JSON::Schema::String class represents a string value in a JSON schema. It is a subclass of JSON::Schema::Leaf and provides methods that can act as constraints.
Instance Method Summary collapse
-
#min(i) ⇒ JSON::Schema::String
Constrain the string to a minimum length.
-
#max(i) ⇒ JSON::Schema::String
Constrain the string to a maximum length.
-
#to_h ⇒ Object
Methods inherited from Leaf
#const, #default, #description, #enum, #initialize, #required, #required?, #to_json
Constructor Details
This class inherits a constructor from JSON::Schema::Leaf
Instance Method Details
#min(i) ⇒ JSON::Schema::String
Constrain the string to a minimum length
14 15 16 |
# File 'lib/json/schema/string.rb', line 14 def min(i) tap { @minimum = i } end |
#max(i) ⇒ JSON::Schema::String
Constrain the string to a maximum length
22 23 24 |
# File 'lib/json/schema/string.rb', line 22 def max(i) tap { @maximum = i } end |
#to_h ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/json/schema/string.rb', line 26 def to_h super.merge!({ type: "string", minLength: @minimum, maxLength: @maximum }).compact end |