Class: Restapi::Validator::NumberValidator

Inherits:
BaseValidator show all
Defined in:
lib/restapi/validator.rb

Instance Attribute Summary

Attributes inherited from BaseValidator

#param_description

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseValidator

#expected_type, find, inherited, #initialize, #param_name, #to_json, #to_s, #valid?

Constructor Details

This class inherits a constructor from Restapi::Validator::BaseValidator

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

#descriptionObject



260
261
262
# File 'lib/restapi/validator.rb', line 260

def description
  "Has to be a number."
end

#errorObject



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