Class: OpenAPIRest::Validators::Pattern

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_rest/validators/pattern.rb

Overview

Rest pattern validator

Instance Method Summary collapse

Constructor Details

#initialize(format, value) ⇒ Pattern

Returns a new instance of Pattern.



7
8
9
10
# File 'lib/openapi_rest/validators/pattern.rb', line 7

def initialize(format, value)
  @format = format
  @value = value
end

Instance Method Details

#error(key) ⇒ Object



16
17
18
# File 'lib/openapi_rest/validators/pattern.rb', line 16

def error(key)
  { key => "invalid format #{@format}" }
end

#valid?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/openapi_rest/validators/pattern.rb', line 12

def valid?
  Regexp.new(@format).match(@value)
end