Class: AFCSalesforce::Tools::Validation::Rule::Phone

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

Overview

Phone rule

Instance Method Summary collapse

Constructor Details

#initialize(params = {:format => :america}) ⇒ Phone

params can be any of the following:

- :format - the phone number format

Example:

{:format => :america}


14
15
16
# File 'lib/afc_salesforce/tools/validation/rule/phone.rb', line 14

def initialize(params = {:format => :america})
  @params = params
end

Instance Method Details

#error(value) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/afc_salesforce/tools/validation/rule/phone.rb', line 23

def error(value)
  digits = value.gsub(/\D/, '').split(//)
  results = {}
  results[:expected] = true
  results[:got] = valid_value?(value)
  results
end

#error_keyObject



36
37
38
# File 'lib/afc_salesforce/tools/validation/rule/phone.rb', line 36

def error_key
  :phone
end

#paramsObject

returns the params given in the constructor



19
20
21
# File 'lib/afc_salesforce/tools/validation/rule/phone.rb', line 19

def params
  @params
end

#valid_value?(value) ⇒ Boolean

determines if value is valid according to the constructor params

Returns:

  • (Boolean)


32
33
34
# File 'lib/afc_salesforce/tools/validation/rule/phone.rb', line 32

def valid_value?(value)
  send(@params[:format], value)
end