Class: Validation::Rule::Phone

Inherits:
Object
  • Object
show all
Defined in:
lib/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}


12
13
14
# File 'lib/validation/rule/phone.rb', line 12

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

Instance Method Details

#error_keyObject



26
27
28
# File 'lib/validation/rule/phone.rb', line 26

def error_key
  :phone
end

#paramsObject

returns the params given in the constructor



17
18
19
# File 'lib/validation/rule/phone.rb', line 17

def params
  @params
end

#valid_value?(value) ⇒ Boolean

determines if value is valid according to the constructor params

Returns:

  • (Boolean)


22
23
24
# File 'lib/validation/rule/phone.rb', line 22

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