Class: Apipie::Validator::NumberValidator

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

Instance Attribute Summary

Attributes inherited from BaseValidator

#param_description

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseValidator

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

Constructor Details

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

Class Method Details

.build(param_description, argument, options, block) ⇒ Object



276
277
278
279
280
# File 'lib/apipie/validator.rb', line 276

def self.build(param_description, argument, options, block)
  if argument == :number
    self.new(param_description)
  end
end

.validate(value) ⇒ Object



286
287
288
# File 'lib/apipie/validator.rb', line 286

def self.validate(value)
  value.to_s =~ /\A(0|[1-9]\d*)\Z$/
end

Instance Method Details

#descriptionObject



282
283
284
# File 'lib/apipie/validator.rb', line 282

def description
  "Must be a number."
end

#validate(value) ⇒ Object



272
273
274
# File 'lib/apipie/validator.rb', line 272

def validate(value)
  self.class.validate(value)
end