Class: MiniDefender::Rules::Numeric

Inherits:
MiniDefender::Rule show all
Defined in:
lib/mini_defender/rules/numeric.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MiniDefender::Rule

#active?, available?, #bails?, #default_value, #defaults?, #error_message, #excluded?, #force_coerce?, #implicit?, make, #priority, #stops?, #with_message

Class Method Details

.signatureObject



4
5
6
# File 'lib/mini_defender/rules/numeric.rb', line 4

def self.signature
  'numeric'
end

Instance Method Details

#coerce(value) ⇒ Object



8
9
10
# File 'lib/mini_defender/rules/numeric.rb', line 8

def coerce(value)
  value.is_a?(Numeric) ? value : Float(value.to_s)
end

#message(attribute, value, validator) ⇒ Object



16
17
18
# File 'lib/mini_defender/rules/numeric.rb', line 16

def message(attribute, value, validator)
  "The field must contain a numeric value."
end

#passes?(attribute, value, validator) ⇒ Boolean

Returns:



12
13
14
# File 'lib/mini_defender/rules/numeric.rb', line 12

def passes?(attribute, value, validator)
  value.is_a?(Numeric) || Float(value.to_s) rescue false
end