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, find, #format_description_value, #ignore_allow_blank?, inherited, #initialize, #inspect, #inspected_fields, #merge_with, #param_name, #params_ordered, raise_if_missing_params, #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



436
437
438
439
440
# File 'lib/apipie/validator.rb', line 436

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

.validate(value) ⇒ Object



450
451
452
# File 'lib/apipie/validator.rb', line 450

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

Instance Method Details

#descriptionObject



442
443
444
# File 'lib/apipie/validator.rb', line 442

def description
  "Must be a decimal number."
end

#expected_typeObject



446
447
448
# File 'lib/apipie/validator.rb', line 446

def expected_type
  'numeric'
end