Class: JsonStructure::Number

Inherits:
Type
  • Object
show all
Defined in:
lib/json_structure/number.rb

Direct Known Subclasses

Integer

Instance Method Summary collapse

Methods inherited from Type

#|

Constructor Details

#initialize(min: nil, max: nil) ⇒ Number

Returns a new instance of Number.



3
4
5
6
# File 'lib/json_structure/number.rb', line 3

def initialize(min: nil, max: nil)
  @min = min
  @max = max
end

Instance Method Details

#===(value) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/json_structure/number.rb', line 8

def ===(value)
  return false unless value.is_a?(::Integer) || value.is_a?(::Float)

  return false if @min && value < @min
  return false if @max && value > @max
  true
end