Class: Rulix::Validators::NumberValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/rulix/validators/number_validator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.to_procObject



4
5
6
# File 'lib/rulix/validators/number_validator.rb', line 4

def self.to_proc
  new.method(:call)
end

Instance Method Details

#call(value) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rulix/validators/number_validator.rb', line 8

def call value
  return [false, error_message] unless value

  case value
  when Integer, Float, Bignum, Fixnum
    true
  when String
    /\A[+-]?\d+\.?\d+?\Z/ === value || [false, error_message]
  else
    [false, error_message]
  end
end

#error_messageObject



21
22
23
# File 'lib/rulix/validators/number_validator.rb', line 21

def error_message
  "is not a number"
end