Class: ShyCouch::Fields::Email_Addr
- Inherits:
-
String
- Object
- String
- ShyCouch::Fields::Email_Addr
- Defined in:
- lib/ShyCouch/fields.rb
Overview
TODO - lightweight validation framework
Instance Method Summary collapse
Instance Method Details
#valid? ⇒ Boolean
6 7 8 9 |
# File 'lib/ShyCouch/fields.rb', line 6 def valid? # Valid if: one and only one '@'; at least one "." after the '@'; an mx record can be resolved at the domain valid_address? and valid_domain? end |
#valid_address? ⇒ Boolean
10 11 12 13 |
# File 'lib/ShyCouch/fields.rb', line 10 def valid_address? self.split("@").length == 2 and self.split("@")[1].split(".").length >= 2 end |
#valid_domain? ⇒ Boolean
14 15 16 17 18 19 |
# File 'lib/ShyCouch/fields.rb', line 14 def valid_domain? domain = self.match(/\@(.+)/)[1] Resolv::DNS.open { |dns| dns.getresources(domain, Resolv::DNS::Resource::IN::MX) }.size > 0 ? true : false rescue Resolv::ResolvError false end |