Class: AFCSalesforce::Tools::Validation::Rule::Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/afc_salesforce/tools/validation/rule/numeric.rb

Overview

rule for numeric values

Instance Method Summary collapse

Instance Method Details

#error(value) ⇒ Object



12
13
14
15
16
17
# File 'lib/afc_salesforce/tools/validation/rule/numeric.rb', line 12

def error(value)
  results = {}
  results[:expected] = true
  results[:got] = valid_value?(value)
  results
end

#error_keyObject

The error key for this rule



20
21
22
# File 'lib/afc_salesforce/tools/validation/rule/numeric.rb', line 20

def error_key
  :numeric
end

#paramsObject

this rule has no params



25
26
27
# File 'lib/afc_salesforce/tools/validation/rule/numeric.rb', line 25

def params
  {}
end

#valid_value?(value) ⇒ Boolean

Determines if value is numeric. It can only contain whole numbers

Returns:

  • (Boolean)


8
9
10
# File 'lib/afc_salesforce/tools/validation/rule/numeric.rb', line 8

def valid_value?(value)
  !!/^[0-9]+$/.match(value.to_s)
end