Class: Apipie::Validator::DecimalValidator

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, #inspect, #inspected_fields, #merge_with, #param_name, #params_ordered, #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



413
414
415
416
417
# File 'lib/apipie/validator.rb', line 413

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

.validate(value) ⇒ Object



423
424
425
# File 'lib/apipie/validator.rb', line 423

def self.validate(value)
  value.to_s =~ /\A^[-+]?[0-9]+([,.][0-9]+)?\Z$/
end

Instance Method Details

#descriptionObject



419
420
421
# File 'lib/apipie/validator.rb', line 419

def description
  "Must be a decimal number."
end

#validate(value) ⇒ Object



409
410
411
# File 'lib/apipie/validator.rb', line 409

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