Class: JSONSkooma::Keywords::Validation::Pattern

Inherits:
Base
  • Object
show all
Defined in:
lib/json_skooma/keywords/validation/pattern.rb

Instance Attribute Summary

Attributes inherited from Base

#json, #parent_schema

Instance Method Summary collapse

Methods inherited from Base

#each_schema, inherited, #instance_types, #key, #resolve, set_defaults, #static, value_schema=

Constructor Details

#initialize(parent_schema, value) ⇒ Pattern

Returns a new instance of Pattern.



10
11
12
13
# File 'lib/json_skooma/keywords/validation/pattern.rb', line 10

def initialize(parent_schema, value)
  super
  @regexp = Regexp.new(value)
end

Instance Method Details

#evaluate(instance, result) ⇒ Object



15
16
17
18
19
# File 'lib/json_skooma/keywords/validation/pattern.rb', line 15

def evaluate(instance, result)
  return if @regexp.match(instance)

  result.failure("The text must match the regular expression #{json.value}")
end