Class: AFCSalesforce::Tools::Validation::Rule::Phone
- Inherits:
-
Object
- Object
- AFCSalesforce::Tools::Validation::Rule::Phone
- Defined in:
- lib/afc_salesforce/tools/validation/rule/phone.rb
Overview
Phone rule
Instance Method Summary collapse
- #error(value) ⇒ Object
- #error_key ⇒ Object
-
#initialize(params = {:format => :america}) ⇒ Phone
constructor
params can be any of the following:.
-
#params ⇒ Object
returns the params given in the constructor.
-
#valid_value?(value) ⇒ Boolean
determines if value is valid according to the constructor params.
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_key ⇒ Object
36 37 38 |
# File 'lib/afc_salesforce/tools/validation/rule/phone.rb', line 36 def error_key :phone end |
#params ⇒ Object
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
32 33 34 |
# File 'lib/afc_salesforce/tools/validation/rule/phone.rb', line 32 def valid_value?(value) send(@params[:format], value) end |