Class: Validator::Email
- Inherits:
-
Object
- Object
- Validator::Email
- Defined in:
- lib/validator/email.rb
Constant Summary collapse
- LOCAL_LENGTH =
64
Instance Attribute Summary collapse
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#local ⇒ Object
Returns the local part (the left hand side of the @ sign in the email address) of the address a = Email.new(‘[email protected]’) a.local #=> ‘vitaliy’.
Instance Method Summary collapse
-
#initialize(value) ⇒ Email
constructor
A new instance of Email.
- #is_email? ⇒ Boolean
- #parse ⇒ Object
-
#valid? ⇒ Boolean
valid if passes all conditions.
- #valid_by_local_length?(local_length = nil) ⇒ Boolean
- #valid_by_regexp? ⇒ Boolean
Constructor Details
#initialize(value) ⇒ Email
Returns a new instance of Email.
12 13 14 15 |
# File 'lib/validator/email.rb', line 12 def initialize(value) @value = value self.parse end |
Instance Attribute Details
#domain ⇒ Object
Returns the value of attribute domain.
3 4 5 |
# File 'lib/validator/email.rb', line 3 def domain @domain end |
#local ⇒ Object
Returns the local part (the left hand side of the @ sign in the email address) of the address
a = Email.new('[email protected]')
a.local #=> 'vitaliy'
8 9 10 |
# File 'lib/validator/email.rb', line 8 def local @local end |
Instance Method Details
#is_email? ⇒ Boolean
21 22 23 |
# File 'lib/validator/email.rb', line 21 def is_email? @value.split(/@/).size == 2 end |
#parse ⇒ Object
17 18 19 |
# File 'lib/validator/email.rb', line 17 def parse @local, @domain = @value.split(/@/) end |
#valid? ⇒ Boolean
valid if passes all conditions
34 35 36 |
# File 'lib/validator/email.rb', line 34 def valid? is_email? and valid_by_local_length? and valid_by_regexp? end |
#valid_by_local_length?(local_length = nil) ⇒ Boolean
25 26 27 |
# File 'lib/validator/email.rb', line 25 def valid_by_local_length?(local_length = nil) @local.length <= (local_length || LOCAL_LENGTH) end |
#valid_by_regexp? ⇒ Boolean
29 30 31 |
# File 'lib/validator/email.rb', line 29 def valid_by_regexp? @value =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i end |