ruby_email 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG +3 -0
- data/README.md +31 -1
- data/lib/ruby_email.rb +30 -0
- data/test/unit_test.rb +12 -0
- data/version +1 -1
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9336b115b34288f687047ab217a43a4386d836cc
|
4
|
+
data.tar.gz: 4937586b0ca515185805c253713b902413b512ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6786779653b217743b5b80400e420df8ec57dc7804039488ad799568da425ab202145691d230f7d2ad5273f7a3e83ec46bd8c4b0b6a4946096bb17ff2bb87a20
|
7
|
+
data.tar.gz: bbc10d88a8309cdb754bd6a11b4fa50f91e920ae9ff40ed3e1ad57ae820d6c11baccb192a0b9932a37b6344064571961b71955508fd8ae3ea7caa914a8fe4021
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,20 @@
|
|
2
2
|
|
3
3
|
Compliant to the [rfc 5322](http://www.ietf.org/rfc/rfc5322.txt) standard.
|
4
4
|
|
5
|
-
##
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```sh
|
8
|
+
gem install ruby_email
|
9
|
+
```
|
10
|
+
|
11
|
+
or in the ``Gemfile``
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'ruby_email'
|
15
|
+
```
|
16
|
+
|
17
|
+
|
18
|
+
## Usage in Ruby
|
6
19
|
|
7
20
|
```ruby
|
8
21
|
require 'ruby_email'
|
@@ -13,14 +26,31 @@ RubyEmail.match "toto@tata" # => #<MatchData "toto@tata" local:"toto" domain:"ta
|
|
13
26
|
"local".is_email? # => false
|
14
27
|
RubyEmail.validates? "toto" # => false
|
15
28
|
RubyEmail.match "toto" # => nil
|
29
|
+
|
30
|
+
"local@domain.root".is_public_email? # => true
|
31
|
+
"local@domain".is_public_email? # => false
|
32
|
+
RubyEmail::Public.validates? "toto@tata.com" # => true
|
33
|
+
RubyEmail::Public.match "toto@tata.com" # => #<MatchData "toto@tata" local:"toto" domain:"tata.com">
|
34
|
+
```
|
35
|
+
|
36
|
+
|
37
|
+
## Usage in Ruby on Rails
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
class Model < ActiveRecord::Base
|
41
|
+
# validates :email, format: RubyEmail::REGEXP # valid on an intranet ...
|
42
|
+
validates :email, format: RubyEmail::Public::REGEXP
|
43
|
+
end
|
16
44
|
```
|
17
45
|
|
46
|
+
|
18
47
|
## Unitary tests
|
19
48
|
|
20
49
|
```sh
|
21
50
|
rake test
|
22
51
|
```
|
23
52
|
|
53
|
+
|
24
54
|
## Contributes !
|
25
55
|
|
26
56
|
Find a bug ? Want a new feature ?
|
data/lib/ruby_email.rb
CHANGED
@@ -26,6 +26,30 @@ module RubyEmail
|
|
26
26
|
str.match(REGEXP)
|
27
27
|
end
|
28
28
|
|
29
|
+
# Only valid on the public internet. "toto@toto" is not valid, but "toto@toto.toto" is good
|
30
|
+
module Public
|
31
|
+
VALIDE = "(?<local>#{DOT_ATOM_TEXT})@(?<domain>#{DOT_ATOM_TEXT}\\.#{DOT_ATOM_TEXT})"
|
32
|
+
REGEXP = Regexp.new "\\A#{VALIDE}\\Z"
|
33
|
+
|
34
|
+
# Check if the {::String} is a valid email on internet
|
35
|
+
# @param str [::String] string to match
|
36
|
+
# @raise [ArgumentError] if str is not a String
|
37
|
+
# @return [TrueClass or FalseClass]
|
38
|
+
def self.validates? str
|
39
|
+
!!match(str)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Check if the string is a valid email on internet and details how
|
43
|
+
# @param str [::String] string to match
|
44
|
+
# @raise [ArgumentError] if str is not a String
|
45
|
+
# @return [MatchData or NilClass] matched email with the keys "local" and "domain"
|
46
|
+
def self.match str
|
47
|
+
raise ArgumentError, "Cannot validate a `#{str.class}`. Only `String` can be." unless str.is_a?(String)
|
48
|
+
str.match(REGEXP)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
29
53
|
# included by {::String}
|
30
54
|
module String
|
31
55
|
# Check if the current [::String] instance is a valid email
|
@@ -33,6 +57,12 @@ module RubyEmail
|
|
33
57
|
def is_email?
|
34
58
|
RubyEmail.validates? self
|
35
59
|
end
|
60
|
+
|
61
|
+
# Check if the current [::String] instance is a valid email on internet
|
62
|
+
# @return [TrueClass or FalseClass]
|
63
|
+
def is_public_email?
|
64
|
+
RubyEmail::Public.validates? self
|
65
|
+
end
|
36
66
|
end
|
37
67
|
|
38
68
|
end
|
data/test/unit_test.rb
CHANGED
@@ -58,3 +58,15 @@ class TestRubyEmail < Test::Unit::TestCase
|
|
58
58
|
end
|
59
59
|
|
60
60
|
end
|
61
|
+
|
62
|
+
class TestRubyEmailPublic < Test::Unit::TestCase
|
63
|
+
def test_simpe
|
64
|
+
assert RubyEmail::Public.validates?("toto@toto.toto")
|
65
|
+
assert RubyEmail::Public.validates?("toto@toto.toto.toto")
|
66
|
+
assert RubyEmail::Public.validates?("toto@toto.toto.toto.toto")
|
67
|
+
assert !RubyEmail::Public.validates?("toto@toto")
|
68
|
+
assert RubyEmail::Public.match("toto@toto.toto")
|
69
|
+
assert "toto@toto.toto".is_public_email?
|
70
|
+
assert !"toto@toto".is_public_email?
|
71
|
+
end
|
72
|
+
end
|
data/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|