Class: JsonStructure::String

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

Instance Method Summary collapse

Methods inherited from Type

#|

Constructor Details

#initialize(min_length: nil, max_length: nil, pattern: nil) ⇒ String

Returns a new instance of String.



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

def initialize(min_length: nil, max_length: nil, pattern: nil)
  @min_length = min_length
  @max_length = max_length
  @pattern = pattern
end

Instance Method Details

#===(value) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/json_structure/string.rb', line 9

def ===(value)
  return false unless value.is_a?(::String)

  return false if @min_length && value.size < @min_length
  return false if @max_length && value.size > @max_length
  return false if @pattern && @pattern !~ value
  true
end