Class: Restapi::Validator::RegexpValidator
Overview
validate arguments value with regular expression
Instance Attribute Summary
#param_name
Class Method Summary
collapse
Instance Method Summary
collapse
find, #to_json, #to_s, #valid?
Constructor Details
Returns a new instance of RegexpValidator.
79
80
81
|
# File 'lib/restapi/validator.rb', line 79
def initialize(argument)
@regexp = argument
end
|
Class Method Details
.build(argument, options, proc) ⇒ Object
87
88
89
|
# File 'lib/restapi/validator.rb', line 87
def self.build(argument, options, proc)
self.new(argument) if argument.is_a? Regexp
end
|
Instance Method Details
#description ⇒ Object
95
96
97
|
# File 'lib/restapi/validator.rb', line 95
def description
"Parameter has to match regular expression /#{@regexp.source}/."
end
|
#error ⇒ Object
91
92
93
|
# File 'lib/restapi/validator.rb', line 91
def error
"Parameter #{@param_name} expecting to match /#{@regexp.source}/, got '#{@error_value}'"
end
|
#validate(value) ⇒ Object
83
84
85
|
# File 'lib/restapi/validator.rb', line 83
def validate(value)
value =~ @regexp
end
|