Class: Restapi::Validator::NumberValidator
Instance Attribute Summary
#param_description
Class Method Summary
collapse
Instance Method Summary
collapse
#expected_type, find, inherited, #initialize, #param_name, #to_json, #to_s, #valid?
Class Method Details
.build(param_description, argument, options, block) ⇒ Object
250
251
252
253
254
|
# File 'lib/restapi/validator.rb', line 250
def self.build(param_description, argument, options, block)
if argument == :number
self.new(param_description)
end
end
|
.validate(value) ⇒ Object
264
265
266
|
# File 'lib/restapi/validator.rb', line 264
def self.validate(value)
value.to_s =~ /\A(0|[1-9]\d*)\Z$/
end
|
Instance Method Details
#description ⇒ Object
260
261
262
|
# File 'lib/restapi/validator.rb', line 260
def description
"Has to be a number."
end
|
#error ⇒ Object
256
257
258
|
# File 'lib/restapi/validator.rb', line 256
def error
"Parameter #{param_name} expecting to be a number, got: #{@error_value}"
end
|
#validate(value) ⇒ Object
246
247
248
|
# File 'lib/restapi/validator.rb', line 246
def validate(value)
self.class.validate(value)
end
|