Class: SimpleJSONSchema::Validators::String

Inherits:
Base
  • Object
show all
Includes:
Concerns::Format
Defined in:
lib/simple_json_schema/validators/string.rb

Constant Summary

Constants included from Concerns::Format

Concerns::Format::ASCII_REGEX, Concerns::Format::DATE_TIME_OFFSET_REGEX, Concerns::Format::EMAIL_REGEX, Concerns::Format::HOSTNAME_REGEX, Concerns::Format::INVALID_QUERY_REGEX, Concerns::Format::LABEL_REGEX_STRING

Instance Method Summary collapse

Methods included from Concerns::Format

#valid_format

Methods inherited from Base

#valid

Instance Method Details

#validate(scope) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/simple_json_schema/validators/string.rb', line 8

def validate(scope)
  value = scope.value

  return scope.error(:string) unless value.is_a?(::String)
  return scope.error(:blank) if scope[:not_blank] == true && value.blank?

  Checker.at_size(scope, :maxLength, :>)
  Checker.at_size(scope, :minLength, :<)

  valid_pattern(scope)
  valid_format(scope)
end