Class: Waw::Validation::FloatValidator

Inherits:
Validator show all
Defined in:
lib/waw/validation/float_validator.rb

Constant Summary collapse

FLOAT_REGEXP =

Regular expression we use

/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/

Instance Method Summary collapse

Methods inherited from Validator

#&, #===, #=~, #initialize, #not, #|

Methods included from Helpers

#all_missing?, #any_missing?, #argument_safe, #error, #is_missing?, #missings_to_nil, #no_missing?, #to_validator

Constructor Details

This class inherits a constructor from Waw::Validation::Validator

Instance Method Details

#convert_and_validate(*values) ⇒ Object



12
13
14
15
# File 'lib/waw/validation/float_validator.rb', line 12

def convert_and_validate(*values)
  ok = values.all?{|v| FLOAT_REGEXP =~ v.to_s}
  ok ? [true, values.collect{|v| v.to_s.to_f}] : [false, values]
end

#validate(*values) ⇒ Object



8
9
10
# File 'lib/waw/validation/float_validator.rb', line 8

def validate(*values)
  values.all?{|v| ::Float===v}
end