Class: Restapi::Validator::RegexpValidator
Overview
validate arguments value with regular expression
Instance Attribute Summary
#param_description
Class Method Summary
collapse
Instance Method Summary
collapse
#expected_type, find, inherited, #param_name, #to_json, #to_s, #valid?
Constructor Details
#initialize(param_description, argument) ⇒ RegexpValidator
Returns a new instance of RegexpValidator.
107
108
109
110
|
# File 'lib/restapi/validator.rb', line 107
def initialize(param_description, argument)
super(param_description)
@regexp = argument
end
|
Class Method Details
.build(param_description, argument, options, proc) ⇒ Object
116
117
118
|
# File 'lib/restapi/validator.rb', line 116
def self.build(param_description, argument, options, proc)
self.new(param_description, argument) if argument.is_a? Regexp
end
|
Instance Method Details
#description ⇒ Object
124
125
126
|
# File 'lib/restapi/validator.rb', line 124
def description
"Parameter has to match regular expression /#{@regexp.source}/."
end
|
#error ⇒ Object
120
121
122
|
# File 'lib/restapi/validator.rb', line 120
def error
"Parameter #{param_name} expecting to match /#{@regexp.source}/, got '#{@error_value}'"
end
|
#validate(value) ⇒ Object
112
113
114
|
# File 'lib/restapi/validator.rb', line 112
def validate(value)
value =~ @regexp
end
|