class AFCSalesforce::Tools::Validation::Rule::Phone
Phone
rule
Public Class Methods
new(params = {:format => :america})
click to toggle source
params can be any of the following:
- :format - the phone number format Example: {:format => :america}
# File lib/afc_salesforce/tools/validation/rule/phone.rb, line 14 def initialize(params = {:format => :america}) @params = params end
Public Instance Methods
error(value)
click to toggle source
# 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_key()
click to toggle source
# File lib/afc_salesforce/tools/validation/rule/phone.rb, line 36 def error_key :phone end
params()
click to toggle source
returns the params given in the constructor
# File lib/afc_salesforce/tools/validation/rule/phone.rb, line 19 def params @params end
valid_value?(value)
click to toggle source
determines if value is valid according to the constructor params
# File lib/afc_salesforce/tools/validation/rule/phone.rb, line 32 def valid_value?(value) send(@params[:format], value) end
Protected Instance Methods
america(value)
click to toggle source
# File lib/afc_salesforce/tools/validation/rule/phone.rb, line 42 def america(value) digits = value.gsub(/\D/, '').split(//) digits.length == 10 || digits.length == 11 end