cregexp 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +20 -0
- data/LICENSE.txt +20 -0
- data/README.md +24 -0
- data/README.textile +24 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/cregexp.rb +33 -0
- data/spec/lib/cregexp_spec.rb +41 -0
- data/spec/spec_helper.rb +3 -0
- data/test/helper.rb +18 -0
- data/test/test_cregexp.rb +7 -0
- metadata +141 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.6.4"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
git (1.2.5)
|
5
|
+
jeweler (1.6.4)
|
6
|
+
bundler (~> 1.0)
|
7
|
+
git (>= 1.2.5)
|
8
|
+
rake
|
9
|
+
rake (0.9.2)
|
10
|
+
rcov (0.9.10)
|
11
|
+
shoulda (2.11.3)
|
12
|
+
|
13
|
+
PLATFORMS
|
14
|
+
ruby
|
15
|
+
|
16
|
+
DEPENDENCIES
|
17
|
+
bundler (~> 1.0.0)
|
18
|
+
jeweler (~> 1.6.4)
|
19
|
+
rcov
|
20
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Hulihan Applications
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Cregexp
|
2
|
+
|
3
|
+
Cregexp is a library of commonly used regular expressions written in ruby.
|
4
|
+
|
5
|
+
## Examples
|
6
|
+
|
7
|
+
### Current Regexps
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
Cregexp.url # /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix
|
11
|
+
Cregexp.email # /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
12
|
+
Cregexp.ip # /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
|
13
|
+
Cregexp.hex # /^#?([a-f0-9]{6}|[a-f0-9]{3})$/
|
14
|
+
```
|
15
|
+
|
16
|
+
### Matching
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
Cregexp.match("http://www.example.com", :url) # true
|
20
|
+
Cregexp.match("http://invalid", :url) # => false
|
21
|
+
|
22
|
+
Cregexp.match("192.168.0.1", :ip) # true
|
23
|
+
Cregexp.match("256.255.255.255", :ip) # false
|
24
|
+
```
|
data/README.textile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
h1. Cregexp
|
2
|
+
|
3
|
+
Cregexp is a library of commonly used regular expressions written in ruby.
|
4
|
+
|
5
|
+
h2. Examples
|
6
|
+
|
7
|
+
h3. Current Regexps
|
8
|
+
|
9
|
+
<pre>
|
10
|
+
Cregexp.url # /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix
|
11
|
+
Cregexp.email # /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
12
|
+
Cregexp.ip # /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
|
13
|
+
Cregexp.hex # /^#?([a-f0-9]{6}|[a-f0-9]{3})$/
|
14
|
+
</pre>
|
15
|
+
|
16
|
+
h2. Matching
|
17
|
+
|
18
|
+
<pre>
|
19
|
+
Cregexp.match("http://www.example.com", :url) # true
|
20
|
+
Cregexp.match("http://invalid", :url) # => false
|
21
|
+
|
22
|
+
Cregexp.match("192.168.0.1", :ip) # true
|
23
|
+
Cregexp.match("256.255.255.255", :ip) # false
|
24
|
+
</pre>
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "cregexp"
|
18
|
+
gem.homepage = "http://github.com/hulihanapplications/cregexp"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Commonly Used Regular Expressions}
|
21
|
+
gem.description = %Q{Cregexp is a library of commonly used regular expressions, written in Ruby.}
|
22
|
+
gem.email = "dave@hulihanapplications.com"
|
23
|
+
gem.authors = ["Hulihan Applications", "Dave Hulihan"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "cregexp #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/cregexp.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
class Cregexp
|
2
|
+
def self.url(options = {})
|
3
|
+
/(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.email(options = {})
|
7
|
+
/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
8
|
+
end
|
9
|
+
|
10
|
+
# Slug
|
11
|
+
# my-title-here passes
|
12
|
+
# my_title_here fails
|
13
|
+
def self.slug(options = {})
|
14
|
+
/^[a-z0-9-]+$/
|
15
|
+
end
|
16
|
+
|
17
|
+
# IP Address
|
18
|
+
def self.ip(options = {})
|
19
|
+
/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
|
20
|
+
end
|
21
|
+
|
22
|
+
# Hex Value
|
23
|
+
# #a3c113 passes
|
24
|
+
# #4d82h4 failes(contains h)
|
25
|
+
def self.hex(options = {})
|
26
|
+
/^#?([a-f0-9]{6}|[a-f0-9]{3})$/
|
27
|
+
end
|
28
|
+
|
29
|
+
# Cregexp.match("http://www.google.com", :url) => true
|
30
|
+
def self.match(string, matcher, options = {})
|
31
|
+
(string =~ send(matcher.to_sym)) == 0
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cregexp do
|
4
|
+
describe "url" do
|
5
|
+
it "should validate http://www.google.com" do
|
6
|
+
string = "http://www.google.com"
|
7
|
+
result = string =~ described_class.url
|
8
|
+
result.should == 0
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should validate http://localhost" do
|
12
|
+
url = "http://localhost"
|
13
|
+
result = url =~ described_class.url
|
14
|
+
#result.should_not == nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "ip" do
|
19
|
+
it "should validate 192.168.0.1" do
|
20
|
+
string = "192.168.0.1"
|
21
|
+
result = string =~ described_class.ip
|
22
|
+
result.should == 0
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should not validate 256.255.255.255" do
|
26
|
+
string = "256.255.255.255"
|
27
|
+
result = string =~ described_class.ip
|
28
|
+
result.should == nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "match" do
|
33
|
+
it "should return true with url matcher and valid url" do
|
34
|
+
described_class.match("http://www.google.com", :url).should == true
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return false with url matcher and invalid url" do
|
38
|
+
described_class.match("httpz://invalid", :url).should == false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'cregexp'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cregexp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Hulihan Applications
|
14
|
+
- Dave Hulihan
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2011-08-17 00:00:00 -06:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
prerelease: false
|
24
|
+
name: shoulda
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
version: "0"
|
34
|
+
requirement: *id001
|
35
|
+
type: :development
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
prerelease: false
|
38
|
+
name: bundler
|
39
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 23
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 0
|
48
|
+
- 0
|
49
|
+
version: 1.0.0
|
50
|
+
requirement: *id002
|
51
|
+
type: :development
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
prerelease: false
|
54
|
+
name: jeweler
|
55
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 7
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 6
|
64
|
+
- 4
|
65
|
+
version: 1.6.4
|
66
|
+
requirement: *id003
|
67
|
+
type: :development
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
prerelease: false
|
70
|
+
name: rcov
|
71
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
requirement: *id004
|
81
|
+
type: :development
|
82
|
+
description: Cregexp is a library of commonly used regular expressions, written in Ruby.
|
83
|
+
email: dave@hulihanapplications.com
|
84
|
+
executables: []
|
85
|
+
|
86
|
+
extensions: []
|
87
|
+
|
88
|
+
extra_rdoc_files:
|
89
|
+
- LICENSE.txt
|
90
|
+
- README.md
|
91
|
+
- README.textile
|
92
|
+
files:
|
93
|
+
- .document
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- README.textile
|
99
|
+
- Rakefile
|
100
|
+
- VERSION
|
101
|
+
- lib/cregexp.rb
|
102
|
+
- spec/lib/cregexp_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
- test/helper.rb
|
105
|
+
- test/test_cregexp.rb
|
106
|
+
has_rdoc: true
|
107
|
+
homepage: http://github.com/hulihanapplications/cregexp
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 3
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
version: "0"
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
hash: 3
|
130
|
+
segments:
|
131
|
+
- 0
|
132
|
+
version: "0"
|
133
|
+
requirements: []
|
134
|
+
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 1.3.7
|
137
|
+
signing_key:
|
138
|
+
specification_version: 3
|
139
|
+
summary: Commonly Used Regular Expressions
|
140
|
+
test_files: []
|
141
|
+
|