validation_demo 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTFkYjViMmE4MDFmYzA0MDQzYjYxMDQyZjRjNDM0ZjJlNmNmNDVmYw==
5
+ data.tar.gz: !binary |-
6
+ YmVlYWJjZjljZWJlZjkwNGY4NzRhYWZlY2JjY2E5NWU0MzhkNTdkMw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OGIyOWM3Mjg1NTE5YThmYTA2NDkzMDFjZmI1MjAxNmFhZTAwZTcxMWFiYWVj
10
+ YTJiNmExMjI0YWU3N2FmMzc2ZTI5ZDU1MzQ1ZTU4Y2I3MWQxNGMxMzNjZTNh
11
+ MDYzOGJkNjBlYjMyNzFlZGJjMDAwZmFhODZkZjgyNzI3MzMyNDU=
12
+ data.tar.gz: !binary |-
13
+ M2RlZGU0ZGI3MDRiNTg5MDEwMGEzMzA1ZTg0ZThmODNmMzIyYWU0OTA4YWVh
14
+ MzlhMjBhOTBjMDY0ZDIwOGQ5M2VjN2Y5YzZmMzQwMDk3YTExZWViMjdjM2I1
15
+ NGI1MDhjMTU0YzZhNTZlNWQ1MjgzN2EyMDAzZjk1NzYwOTA0MmI=
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
File without changes
@@ -0,0 +1,22 @@
1
+ require 'resolv'
2
+ class ValidationDemo
3
+
4
+ def self.validate(email, validate_mx = false)
5
+ email_pattern = (email =~ /^[a-zA-Z][\w\.\+-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/)
6
+ is_valid = email_pattern.nil? ? false : true
7
+ is_valid = validate_mx_record(email) if is_valid && validate_mx
8
+
9
+ return is_valid
10
+ end
11
+
12
+ def self.validate_mx_record(email)
13
+ domain = email.match(/\@(.+)/)[1]
14
+ Resolv::DNS.open do |dns|
15
+ @mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX)
16
+ end
17
+ @mx.size > 0 ? true : false
18
+ end
19
+
20
+ end
21
+
22
+
@@ -0,0 +1,47 @@
1
+ require 'test/unit'
2
+ require 'validation_demo'
3
+
4
+ class ValidationDemoTest < Test::Unit::TestCase
5
+ def test_validation_email
6
+ assert_not_valid("bvsatyaram")
7
+ assert_not_valid("bvsatyaram@example")
8
+ assert_not_valid("bvsatyaram.com")
9
+ assert_valid("bvsatyaram@example.com")
10
+ assert_valid("bv_satyaram@example.com")
11
+ assert_valid("bv.satyaram@example.com")
12
+ assert_valid("bv-satyaram@example.com")
13
+ assert_valid("bvsatyaram@example.org")
14
+ assert_valid("bvsatyaram@fhgtrityhgs.com")
15
+
16
+ assert_not_valid("bvsatyaram", true)
17
+ assert_not_valid("bvsatyaram@example", true)
18
+ assert_not_valid("bvsatyaram.com", true)
19
+ assert_valid("bvsatyaram@bvsatyaram.com", true)
20
+ assert_valid("bv_satyaram@bvsatyaram.com", true)
21
+ assert_valid("bv.satyaram@bvsatyaram.com", true)
22
+ assert_valid("bv-satyaram@bvsatyaram.com", true)
23
+ assert_valid("bvsatyaram@rubygems.org", true)
24
+ assert_valid("bv12.satyaram@rubygems.org", true)
25
+ assert_valid("bvsatyaram+google@bvsatyaram.com", true)
26
+ assert_valid("bv.satya_ram-123+google123@bvsatyaram.com", true)
27
+ assert_not_valid("bvsatyaram@fhgtrityhgs.com", true)
28
+ end
29
+
30
+ private
31
+ def assert_valid(email, validate_mx = nil)
32
+ if validate_mx.nil?
33
+ assert_equal true, ValidationDemo.validate(email)
34
+ else
35
+ assert_equal true, ValidationDemo.validate(email, validate_mx)
36
+ end
37
+ end
38
+
39
+ def assert_not_valid(email, validate_mx = nil)
40
+ if validate_mx.nil?
41
+ assert_equal false, ValidationDemo.validate(email)
42
+ else
43
+ assert_equal false, ValidationDemo.validate(email, validate_mx)
44
+ end
45
+ end
46
+
47
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: validation_demo
3
+ version: !ruby/object:Gem::Version
4
+ version: 5.0.0
5
+ platform: ruby
6
+ authors:
7
+ - ketan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Use Validation for Email in ruby
14
+ email: mketanv@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - Rakefile
20
+ - bin/validation_demo
21
+ - lib/validation_demo.rb
22
+ - test/test_validation_demo.rb
23
+ homepage: http://rubygems.org/gems/validation_demo
24
+ licenses: []
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.3.0
43
+ signing_key:
44
+ specification_version: 3
45
+ summary: Validation of Email!
46
+ test_files:
47
+ - test/test_validation_demo.rb
48
+ has_rdoc: