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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 695c3ef1a1b8f15a41b409e40c21a9faf29916cf
4
- data.tar.gz: 9e4ca4b2e7dd6e295e6e6e883d1873a1b4adbda4
3
+ metadata.gz: 9336b115b34288f687047ab217a43a4386d836cc
4
+ data.tar.gz: 4937586b0ca515185805c253713b902413b512ab
5
5
  SHA512:
6
- metadata.gz: c16f25b5502ac66803ee478512a8e917ab9701c262a2ff6029a126b0cc63803ded73d6fb34bf867a7fc1534e0597742e69145064426a589d8a0715df00d60798
7
- data.tar.gz: 9be99178fe6a3b6bf55e5ae39fcd02a53fcb66347845d68bbfaf5bccd0a178593a05e84277f7618f4ab185d7418eee5299628f5067289222052d0874ad8ef9a5
6
+ metadata.gz: 6786779653b217743b5b80400e420df8ec57dc7804039488ad799568da425ab202145691d230f7d2ad5273f7a3e83ec46bd8c4b0b6a4946096bb17ff2bb87a20
7
+ data.tar.gz: bbc10d88a8309cdb754bd6a11b4fa50f91e920ae9ff40ed3e1ad57ae820d6c11baccb192a0b9932a37b6344064571961b71955508fd8ae3ea7caa914a8fe4021
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ v0.1.4
2
+ * Add public features (to check if the email is valid on the internet)
3
+
1
4
  v0.1.3
2
5
  * Rename the gem to be standard compliant
3
6
 
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
- ## Usage
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.3
1
+ 0.1.4
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nephos (poulet_a)
metadata.gz.sig CHANGED
Binary file