regex_glossary 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +21 -0
- data/Rakefile +11 -0
- data/lib/regex_glossary.rb +7 -0
- data/lib/regex_glossary/version.rb +3 -0
- data/regex_glossary.gemspec +22 -0
- data/test/fixtures/email_lists.yml +9 -0
- data/test/fixtures/emails.yml +38 -0
- data/test/fixtures/postal_codes.yml +8 -0
- data/test/regex_glossary_test.rb +27 -0
- data/test/test_helper.rb +23 -0
- metadata +97 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Earlydoc
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Earlydoc Regular Expression Glossary
|
2
|
+
|
3
|
+
This gem contains a module of regular expressions objects for consistent validation and business logic.
|
4
|
+
|
5
|
+
Expressions
|
6
|
+
===========
|
7
|
+
|
8
|
+
RegexGlossary::Email
|
9
|
+
RegexGlossary::EmailList
|
10
|
+
RegexGlossary::DutchPostalCode
|
11
|
+
|
12
|
+
Usage
|
13
|
+
===========
|
14
|
+
|
15
|
+
For example, to use with model validation require the library and reference one of the expression constants:
|
16
|
+
|
17
|
+
require "regex_glossary"
|
18
|
+
|
19
|
+
...
|
20
|
+
|
21
|
+
validates_format_of :email, :with => RegexGlossary::Email
|
data/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
module RegexGlossary
|
2
|
+
DutchPostalCode = /^[1-9][0-9]{3}\s?[a-z]{2}$/i
|
3
|
+
|
4
|
+
# REF: http://fightingforalostcause.net/misc/2006/compare-email-regex.php
|
5
|
+
Email = /\A([\w\!\#\z\%\&\'\*\+\-\/\=\?\\A\`{\|\}\~]+\.)*[\w-]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)\z/i
|
6
|
+
EmailList = /(\A([\w\!\#\z\%\&\'\*\+\-\/\=\?\\A\`{\|\}\~]+\.)*[\w-]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)\s*(,|\z)+)/i
|
7
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'regex_glossary/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "regex_glossary"
|
8
|
+
spec.version = RegexGlossary::VERSION
|
9
|
+
spec.summary = "Earlydoc Regular Expression Glossary"
|
10
|
+
spec.description = "This gem contains a module of regular expressions objects for consistent validation and business logic."
|
11
|
+
spec.authors = ['Earlydoc', 'Travis Dunn']
|
12
|
+
spec.email = 'developer@earlydoc.com'
|
13
|
+
spec.homepage = 'https://www.earlydoc.com'
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
valid:
|
2
|
+
- "one@example.com"
|
3
|
+
- "first@example.com,second@example.com"
|
4
|
+
- "first@example.com, secondwithspace@example.com"
|
5
|
+
- "first@example.com ,secondwithspace@example.com"
|
6
|
+
invalid:
|
7
|
+
- ",,frontcommas@example.com"
|
8
|
+
- "invalidemailaddress,valid@example.com"
|
9
|
+
- "only@example.com spaceseparator@example.com"
|
@@ -0,0 +1,38 @@
|
|
1
|
+
valid:
|
2
|
+
- "l3tt3rsAndNumb3rs@domain.com"
|
3
|
+
- "has-dash@domain.com"
|
4
|
+
- "uncommonTLD@domain.museum"
|
5
|
+
- "uncommonTLD@domain.travel"
|
6
|
+
- "uncommonTLD@domain.mobi"
|
7
|
+
- "countryCodeTLD@domain.uk"
|
8
|
+
- "countryCodeTLD@domain.rw"
|
9
|
+
- "lettersInDomain@911.com"
|
10
|
+
- "underscore_inLocal@domain.net"
|
11
|
+
- "subdomain@sub.domain.com"
|
12
|
+
- "local@dash-inDomain.com"
|
13
|
+
- "dot.inLocal@foo.com"
|
14
|
+
- "a@singleLetterLocal.org"
|
15
|
+
- "singleLetterDomain@x.org"
|
16
|
+
- "foor@bar.newTLD"
|
17
|
+
invalid:
|
18
|
+
- "@missingLocal.org"
|
19
|
+
- "someone-else@127.0.0.1.26"
|
20
|
+
- "missingdomain@.com"
|
21
|
+
- "missingatSign.net"
|
22
|
+
- "missingDot@com"
|
23
|
+
- "two@@signs.com"
|
24
|
+
- "colonButNoPort@127.0.0.1:"
|
25
|
+
- ""
|
26
|
+
- "&*=?^+{}'~@validCharsInLocal.net"
|
27
|
+
- "hasApostrophe.o'leary@domain.org"
|
28
|
+
- ".localStartsWithDot@domain.com"
|
29
|
+
- "localEndsWithDot.@domain.com"
|
30
|
+
- "two..consecutiveDots@domain.com"
|
31
|
+
- "domainStartsWithDash@-domain.com"
|
32
|
+
- "domainEndsWithDash@domain-.com"
|
33
|
+
- "numbersInTLD@domain.c0m"
|
34
|
+
- "mike!@gmail.com"
|
35
|
+
- "missingTLD@domain."
|
36
|
+
- "! #$%(),/;<>[]`|@invalidCharsInLocal.org"
|
37
|
+
- "invalidCharsInDomain@! #$%(),/;<>_[]`|.org"
|
38
|
+
- "local@SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class RegexGlossaryTest < MiniTest::Unit::TestCase
|
4
|
+
def test_valid_emails
|
5
|
+
assert_valid_regex RegexGlossary::Email, load_fixture('emails')['valid']
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_invalid_emails
|
9
|
+
assert_invalid_regex RegexGlossary::Email, load_fixture('emails')["invalid"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_valid_email_lists
|
13
|
+
assert_valid_regex RegexGlossary::EmailList, load_fixture('email_lists')['valid']
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_invalid_email_lists
|
17
|
+
assert_invalid_regex RegexGlossary::EmailList, load_fixture('email_lists')["invalid"]
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_valid_postal_codes
|
21
|
+
assert_valid_regex RegexGlossary::DutchPostalCode, load_fixture('postal_codes')['valid']
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_invalid_postal_codes
|
25
|
+
assert_invalid_regex RegexGlossary::DutchPostalCode, load_fixture('postal_codes')["invalid"]
|
26
|
+
end
|
27
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'ansi/code'
|
2
|
+
require 'turn'
|
3
|
+
require 'yaml'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require_relative '../lib/regex_glossary'
|
6
|
+
|
7
|
+
class MiniTest::Unit::TestCase
|
8
|
+
def load_fixture(name)
|
9
|
+
YAML.load( File.read( File.join( File.dirname(__FILE__), 'fixtures', "#{name}.yml" ) ) )
|
10
|
+
end
|
11
|
+
|
12
|
+
def assert_valid_regex(regexp, strings)
|
13
|
+
strings.each do |str|
|
14
|
+
assert str =~ regexp, "#{str} should be valid but it is not"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def assert_invalid_regex(regexp, strings)
|
19
|
+
strings.each do |str|
|
20
|
+
assert str !~ regexp, "#{str} should be invalid but it is not"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: regex_glossary
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Earlydoc
|
9
|
+
- Travis Dunn
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-05-27 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.3'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '1.3'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: rake
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
description: This gem contains a module of regular expressions objects for consistent
|
48
|
+
validation and business logic.
|
49
|
+
email: developer@earlydoc.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- lib/regex_glossary.rb
|
60
|
+
- lib/regex_glossary/version.rb
|
61
|
+
- regex_glossary.gemspec
|
62
|
+
- test/fixtures/email_lists.yml
|
63
|
+
- test/fixtures/emails.yml
|
64
|
+
- test/fixtures/postal_codes.yml
|
65
|
+
- test/regex_glossary_test.rb
|
66
|
+
- test/test_helper.rb
|
67
|
+
homepage: https://www.earlydoc.com
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.8.24
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Earlydoc Regular Expression Glossary
|
92
|
+
test_files:
|
93
|
+
- test/fixtures/email_lists.yml
|
94
|
+
- test/fixtures/emails.yml
|
95
|
+
- test/fixtures/postal_codes.yml
|
96
|
+
- test/regex_glossary_test.rb
|
97
|
+
- test/test_helper.rb
|