Class: JSON::Schema::Integer

Inherits:
Leaf
  • Object
show all
Defined in:
lib/json/schema/integer.rb

Overview

The JSON::Schema::Integer class represents a whole number 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

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::Number

Constrain the number to a minimum value

Parameters:

  • i (Integer)

    The minimum value

Returns:



14
15
16
# File 'lib/json/schema/integer.rb', line 14

def min(i)
  tap { @minimum = i }
end

#max(i) ⇒ JSON::Schema::Number

Constrain the number to a maximum value

Parameters:

  • i (Integer)

    The maximum value

Returns:



22
23
24
# File 'lib/json/schema/integer.rb', line 22

def max(i)
  tap { @maximum = i }
end

#multiple_of(i) ⇒ JSON::Schema::Number

Constrain the number to a multiple of a given value

Parameters:

Returns:



30
31
32
# File 'lib/json/schema/integer.rb', line 30

def multiple_of(i)
  tap { @multiple_of = i }
end

#to_hObject



34
35
36
37
38
39
40
41
# File 'lib/json/schema/integer.rb', line 34

def to_h
  super.merge!({
    type: "integer",
    minimum: @minimum,
    maximum: @maximum,
    multipleOf: @multiple_of
  }).compact
end