class SimpleJSONSchema::Validators::String

Public Instance Methods

validate(scope) click to toggle source
# 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

Private Instance Methods

valid_pattern(scope) click to toggle source
# File lib/simple_json_schema/validators/string.rb, line 23
def valid_pattern(scope)
  pattern = scope[:pattern]
  return if pattern.nil?

  match = RegexHelper.ecma_262_regex(pattern, scope.cache).match?(scope.value)
  return if match

  scope.error(:pattern)
end