ruby_regex 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,4 @@
1
+ 30/4/2010
2
+ -------------------------
3
+ Add RubyRegex::Username
4
+ Add RubyRegex::Dni
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010, Emili Parreño
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,23 @@
1
+ = RubyRegex
2
+
3
+ Ruby regular expressions library
4
+
5
+ == Methods
6
+
7
+ RubyRegex::Url
8
+ RubyRegex::Domain
9
+ RubyRegex::Email
10
+ RubyRegex::ZipCode
11
+
12
+ == Rails
13
+
14
+ # config/environment.rb
15
+ config.gem ruby_regex
16
+
17
+
18
+ # models
19
+ validates_format_of :email, :with => RubyRegex::Email
20
+
21
+ ---
22
+
23
+ RubyRegex is released under the MIT-License and is Copyright (c)2010 Emili Parreño.
data/lib/ruby_regex.rb CHANGED
@@ -1,10 +1,17 @@
1
1
  module RubyRegex
2
+ # Username
3
+ # This regular expression doesn't validate username's length
4
+ Username = /^[a-zA-Z0-9_]*$/
5
+
6
+ # Dni (spanish ID card)
7
+ Dni = /^\d{8}[A-Za-z]{1}$/
8
+
2
9
  # URL Regex
3
- URL = /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix
10
+ Url = URL = /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix
4
11
 
5
12
  # Domain Regex
6
13
  Domain = /(^$)|(^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?)?$)/ix
7
-
14
+
8
15
  # MasterCard Regex
9
16
  MasterCard = /^5[1-5]\d{14}$/
10
17
 
@@ -5,6 +5,38 @@ require 'active_support/test_case'
5
5
  require 'ruby_regex'
6
6
 
7
7
  class RubyRegexTest < ActiveSupport::TestCase
8
+ def test_valid_usernames
9
+ usernames = ['test', 'test_test', 'test1', 'test_1']
10
+ usernames.each do |username|
11
+ message = build_message(message, '<?> do not pass the test', username)
12
+ assert(username =~ RubyRegex::Username, username)
13
+ end
14
+ end
15
+
16
+ def test_invalid_usernames
17
+ usernames = ['test-test', 'test.test', 'test/test', 'test@test']
18
+ usernames.each do |username|
19
+ message = build_message(message, '<?> do not pass the test', username)
20
+ assert(username !~ RubyRegex::Username, username)
21
+ end
22
+ end
23
+
24
+ def test_valid_dnis
25
+ dnis = ['40990889J', '99888777h']
26
+ dnis.each do |dni|
27
+ message = build_message(message, '<?> do not pass the test', dni)
28
+ assert(dni =~ RubyRegex::Username, dni)
29
+ end
30
+ end
31
+
32
+ def test_invalid_dnis
33
+ dnis = ['90.900.900V', '90900900-V']
34
+ dnis.each do |dni|
35
+ message = build_message(message, '<?> do not pass the test', dni)
36
+ assert(dni !~ RubyRegex::Username, dni)
37
+ end
38
+ end
39
+
8
40
  def test_valid_emails
9
41
  emails = ['test@test.com', 'test@test.co.uk', 'test@test.es', 'test@test.info']
10
42
  emails.each do |email|
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Emili Parreno
@@ -27,10 +27,12 @@ extensions: []
27
27
  extra_rdoc_files: []
28
28
 
29
29
  files:
30
- - README
30
+ - CHANGELOG
31
+ - README.rdoc
32
+ - LICENSE
31
33
  - lib/ruby_regex.rb
32
34
  has_rdoc: true
33
- homepage: http://www.eparreno.com
35
+ homepage: http://github.com/eparreno/ruby_regex
34
36
  licenses: []
35
37
 
36
38
  post_install_message:
data/README DELETED
File without changes