cregexp 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,10 +7,11 @@ Cregexp is a library of commonly used regular expressions written in ruby.
7
7
  ### Current Regexps
8
8
 
9
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})$/
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
+ Cregexp.image # /.png|.jpg|.jpeg|.gif|.bmp|.tiff|.PNG|.JPG|.JPEG|.GIF|.BMP|.TIFF$/
14
15
  ```
15
16
 
16
17
  ### Matching
@@ -21,4 +22,23 @@ Cregexp.match("http://invalid", :url) # => false
21
22
 
22
23
  Cregexp.match("192.168.0.1", :ip) # true
23
24
  Cregexp.match("256.255.255.255", :ip) # false
25
+ ```
26
+
27
+ ## Using Cregexp in Rails 3.x
28
+
29
+ Add this to your app's Gemfile:
30
+
31
+ ```ruby
32
+ gem "cregexp"
33
+ ```
34
+
35
+ That's It! Now Use it in a model for easy validations:
36
+
37
+
38
+ ```ruby
39
+ class Image < ActiveRecord::Base
40
+ validates_format_of :file, :format => Cregexp.image
41
+
42
+ ...
43
+ end
24
44
  ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{cregexp}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Hulihan Applications", "Dave Hulihan"]
12
+ s.date = %q{2011-08-22}
13
+ s.description = %q{Cregexp is a library of commonly used regular expressions, written in Ruby.}
14
+ s.email = %q{dave@hulihanapplications.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "cregexp.gemspec",
28
+ "lib/cregexp.rb",
29
+ "spec/lib/cregexp_spec.rb",
30
+ "spec/spec_helper.rb",
31
+ "test/helper.rb",
32
+ "test/test_cregexp.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/hulihanapplications/cregexp}
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.7.2}
38
+ s.summary = %q{Commonly Used Regular Expressions}
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
45
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
46
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
47
+ s.add_development_dependency(%q<rcov>, [">= 0"])
48
+ else
49
+ s.add_dependency(%q<shoulda>, [">= 0"])
50
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
51
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
52
+ s.add_dependency(%q<rcov>, [">= 0"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<shoulda>, [">= 0"])
56
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
58
+ s.add_dependency(%q<rcov>, [">= 0"])
59
+ end
60
+ end
61
+
@@ -26,8 +26,14 @@ class Cregexp
26
26
  /^#?([a-f0-9]{6}|[a-f0-9]{3})$/
27
27
  end
28
28
 
29
+ # Image
30
+ # Checke if file extension is of a valid image type
31
+ def self.image
32
+ /.png|.jpg|.jpeg|.gif|.bmp|.tiff|.PNG|.JPG|.JPEG|.GIF|.BMP|.TIFF$/
33
+ end
34
+
29
35
  # Cregexp.match("http://www.google.com", :url) => true
30
36
  def self.match(string, matcher, options = {})
31
- (string =~ send(matcher.to_sym)) == 0
37
+ !(string =~ send(matcher.to_sym)).nil?
32
38
  end
33
39
  end
@@ -30,12 +30,25 @@ describe Cregexp do
30
30
  end
31
31
 
32
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
33
+ describe "url" do
34
+ it "should return true with valid url" do
35
+ described_class.match("http://www.google.com", :url).should == true
36
+ end
37
+
38
+ it "should return false with invalid url" do
39
+ described_class.match("httpz://invalid", :url).should == false
40
+ end
41
+ end
42
+
43
+ describe "image" do
44
+ it "should return true with valid filename" do
45
+ described_class.match("image.png", :image).should == true
46
+ end
36
47
 
37
- it "should return false with url matcher and invalid url" do
38
- described_class.match("httpz://invalid", :url).should == false
39
- end
48
+ it "should return false with invalid filename" do
49
+ described_class.match("image.jperg", :image).should == false
50
+ end
51
+ end
52
+
40
53
  end
41
54
  end
metadata CHANGED
@@ -1,141 +1,109 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
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
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Hulihan Applications
14
9
  - Dave Hulihan
15
10
  autorequire:
16
11
  bindir: bin
17
12
  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
13
+ date: 2011-08-22 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
24
16
  name: shoulda
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &76067610 !ruby/object:Gem::Requirement
26
18
  none: false
27
- requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- hash: 3
31
- segments:
32
- - 0
33
- version: "0"
34
- requirement: *id001
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
35
23
  type: :development
36
- - !ruby/object:Gem::Dependency
37
24
  prerelease: false
25
+ version_requirements: *76067610
26
+ - !ruby/object:Gem::Dependency
38
27
  name: bundler
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
28
+ requirement: &76066860 !ruby/object:Gem::Requirement
40
29
  none: false
41
- requirements:
30
+ requirements:
42
31
  - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 23
45
- segments:
46
- - 1
47
- - 0
48
- - 0
32
+ - !ruby/object:Gem::Version
49
33
  version: 1.0.0
50
- requirement: *id002
51
34
  type: :development
52
- - !ruby/object:Gem::Dependency
53
35
  prerelease: false
36
+ version_requirements: *76066860
37
+ - !ruby/object:Gem::Dependency
54
38
  name: jeweler
55
- version_requirements: &id003 !ruby/object:Gem::Requirement
39
+ requirement: &76066540 !ruby/object:Gem::Requirement
56
40
  none: false
57
- requirements:
41
+ requirements:
58
42
  - - ~>
59
- - !ruby/object:Gem::Version
60
- hash: 7
61
- segments:
62
- - 1
63
- - 6
64
- - 4
43
+ - !ruby/object:Gem::Version
65
44
  version: 1.6.4
66
- requirement: *id003
67
45
  type: :development
68
- - !ruby/object:Gem::Dependency
69
46
  prerelease: false
47
+ version_requirements: *76066540
48
+ - !ruby/object:Gem::Dependency
70
49
  name: rcov
71
- version_requirements: &id004 !ruby/object:Gem::Requirement
50
+ requirement: &76066040 !ruby/object:Gem::Requirement
72
51
  none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- hash: 3
77
- segments:
78
- - 0
79
- version: "0"
80
- requirement: *id004
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
81
56
  type: :development
82
- description: Cregexp is a library of commonly used regular expressions, written in Ruby.
57
+ prerelease: false
58
+ version_requirements: *76066040
59
+ description: Cregexp is a library of commonly used regular expressions, written in
60
+ Ruby.
83
61
  email: dave@hulihanapplications.com
84
62
  executables: []
85
-
86
63
  extensions: []
87
-
88
- extra_rdoc_files:
64
+ extra_rdoc_files:
89
65
  - LICENSE.txt
90
66
  - README.md
91
- - README.textile
92
- files:
67
+ files:
93
68
  - .document
94
69
  - Gemfile
95
70
  - Gemfile.lock
96
71
  - LICENSE.txt
97
72
  - README.md
98
- - README.textile
99
73
  - Rakefile
100
74
  - VERSION
75
+ - cregexp.gemspec
101
76
  - lib/cregexp.rb
102
77
  - spec/lib/cregexp_spec.rb
103
78
  - spec/spec_helper.rb
104
79
  - test/helper.rb
105
80
  - test/test_cregexp.rb
106
- has_rdoc: true
107
81
  homepage: http://github.com/hulihanapplications/cregexp
108
- licenses:
82
+ licenses:
109
83
  - MIT
110
84
  post_install_message:
111
85
  rdoc_options: []
112
-
113
- require_paths:
86
+ require_paths:
114
87
  - lib
115
- required_ruby_version: !ruby/object:Gem::Requirement
88
+ required_ruby_version: !ruby/object:Gem::Requirement
116
89
  none: false
117
- requirements:
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- hash: 3
121
- segments:
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ segments:
122
95
  - 0
123
- version: "0"
124
- required_rubygems_version: !ruby/object:Gem::Requirement
96
+ hash: -85634639
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
98
  none: false
126
- requirements:
127
- - - ">="
128
- - !ruby/object:Gem::Version
129
- hash: 3
130
- segments:
131
- - 0
132
- version: "0"
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
133
103
  requirements: []
134
-
135
104
  rubyforge_project:
136
- rubygems_version: 1.3.7
105
+ rubygems_version: 1.7.2
137
106
  signing_key:
138
107
  specification_version: 3
139
108
  summary: Commonly Used Regular Expressions
140
109
  test_files: []
141
-
@@ -1,24 +0,0 @@
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>