regexpert 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 [Matthew Rudy Jacobs]
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 ADDED
@@ -0,0 +1,18 @@
1
+ Regexpert
2
+ =========
3
+
4
+ Regexpert is an attempt to remove the need to worry about which regular expression to use for validating an email, a postcode, or a social security number.
5
+ Its inspired by the django.contrib.localflavor libraries and Datamapper dm-more's dm-validations module.
6
+
7
+ Example
8
+ =======
9
+
10
+ Instead of googling "email regexp", and then coming up with numerous arguments about the right regexp to use,
11
+ just use Regexpert
12
+
13
+ validates_format_of :email, :with => Regexpert::Format::EmailAddress
14
+
15
+ BOOM!!!
16
+ no work, no worries.
17
+
18
+ Copyright (c) 2008 [Matthew Rudy Jacobs], released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,83 @@
1
+ require "rubygems"
2
+ require "rubygems/package_task"
3
+ require "rdoc/task"
4
+
5
+ require "rake/testtask"
6
+ Rake::TestTask.new do |t|
7
+ t.libs << "test"
8
+ t.test_files = FileList["test/**/*_test.rb"]
9
+ t.verbose = true
10
+ end
11
+
12
+
13
+ task :default => ["test"]
14
+
15
+ # This builds the actual gem. For details of what all these options
16
+ # mean, and other ones you can add, check the documentation here:
17
+ #
18
+ # http://rubygems.org/read/chapter/20
19
+ #
20
+
21
+ spec = Gem::Specification.new do |s|
22
+
23
+ # Change these as appropriate
24
+ s.name = "regexpert"
25
+ s.version = "0.0.2"
26
+ s.summary = "A bunch of useful Regular expressions"
27
+ s.description = "Regular expressions bundled into a single place, so you dont have to think anymore about what email regexp to use."
28
+
29
+ s.author = "Matthew Rudy Jacobs"
30
+ s.email = "MatthewRudyJacobs@gmail.com"
31
+ s.homepage = "http://github.com/matthewrudy/regexpert"
32
+
33
+ s.has_rdoc = true
34
+ s.extra_rdoc_files = %w(README)
35
+ s.rdoc_options = %w(--main README)
36
+
37
+ # Add any extra files to include in the gem
38
+ s.files = %w(MIT-LICENSE Rakefile README) + Dir.glob("{test,lib}/**/*")
39
+ s.require_paths = ["lib"]
40
+
41
+ # If you want to depend on other gems, add them here, along with any
42
+ # relevant versions
43
+ # s.add_dependency("some_other_gem", "~> 0.1.0")
44
+
45
+ # If your tests use any gems, include them here
46
+ # s.add_development_dependency("mocha") # for example
47
+ end
48
+
49
+ # This task actually builds the gem. We also regenerate a static
50
+ # .gemspec file, which is useful if something (i.e. GitHub) will
51
+ # be automatically building a gem for this project. If you're not
52
+ # using GitHub, edit as appropriate.
53
+ #
54
+ # To publish your gem online, install the 'gemcutter' gem; Read more
55
+ # about that here: http://gemcutter.org/pages/gem_docs
56
+ Gem::PackageTask.new(spec) do |pkg|
57
+ pkg.gem_spec = spec
58
+ end
59
+
60
+ desc "Build the gemspec file #{spec.name}.gemspec"
61
+ task :gemspec do
62
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
63
+ File.open(file, "w") {|f| f << spec.to_ruby }
64
+ end
65
+
66
+ # If you don't want to generate the .gemspec file, just remove this line. Reasons
67
+ # why you might want to generate a gemspec:
68
+ # - using bundler with a git source
69
+ # - building the gem without rake (i.e. gem build blah.gemspec)
70
+ # - maybe others?
71
+ task :package => :gemspec
72
+
73
+ # Generate documentation
74
+ RDoc::Task.new do |rd|
75
+ rd.main = "README"
76
+ rd.rdoc_files.include("README", "lib/**/*.rb")
77
+ rd.rdoc_dir = "rdoc"
78
+ end
79
+
80
+ desc 'Clear out RDoc and generated packages'
81
+ task :clean => [:clobber_rdoc, :clobber_package] do
82
+ rm "#{spec.name}.gemspec"
83
+ end
data/lib/regexpert.rb ADDED
@@ -0,0 +1,76 @@
1
+ module Regexpert
2
+ module Format
3
+ # This is taken from dm-more - http://github.com/sam/dm-more/tree/master/dm-validations/lib/dm-validations/formats/email.rb
4
+ # RFC2822 (No attribution reference available)
5
+ #
6
+ # doctest: email_address
7
+ # >> "MatthewRudyJacobs@gmail.com" =~ Regexpert::Format::EmailAddress
8
+ # => 0
9
+ #
10
+ # >> "dev@" =~ Regexpert::Format::EmailAddress
11
+ # => nil
12
+ #
13
+ EmailAddress = begin
14
+ alpha = "a-zA-Z"
15
+ digit = "0-9"
16
+ atext = "[#{alpha}#{digit}\!\#\$\%\&\'\*+\/\=\?\^\_\`\{\|\}\~\-]"
17
+ dot_atom_text = "#{atext}+([.]#{atext}*)*"
18
+ dot_atom = "#{dot_atom_text}"
19
+ qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'
20
+ text = "[\\x01-\\x09\\x11\\x12\\x14-\\x7f]"
21
+ quoted_pair = "(\\x5c#{text})"
22
+ qcontent = "(?:#{qtext}|#{quoted_pair})"
23
+ quoted_string = "[\"]#{qcontent}+[\"]"
24
+ atom = "#{atext}+"
25
+ word = "(?:#{atom}|#{quoted_string})"
26
+ obs_local_part = "#{word}([.]#{word})*"
27
+ local_part = "(?:#{dot_atom}|#{quoted_string}|#{obs_local_part})"
28
+ no_ws_ctl = "\\x01-\\x08\\x11\\x12\\x14-\\x1f\\x7f"
29
+ dtext = "[#{no_ws_ctl}\\x21-\\x5a\\x5e-\\x7e]"
30
+ dcontent = "(?:#{dtext}|#{quoted_pair})"
31
+ domain_literal = "\\[#{dcontent}+\\]"
32
+ obs_domain = "#{atom}([.]#{atom})*"
33
+ domain = "(?:#{dot_atom}|#{domain_literal}|#{obs_domain})"
34
+ addr_spec = "#{local_part}\@#{domain}"
35
+ pattern = /^#{addr_spec}$/
36
+ end
37
+
38
+ # This is taken from dm-more http://github.com/sam/dm-more/tree/master/dm-validations/lib/dm-validations/formats/url.rb
39
+ # Regex from http://www.igvita.com/2006/09/07/validating-url-in-ruby-on-rails/
40
+ #
41
+ # doctest: url # examples from Rails auto_link tests
42
+ # >> "http://www.rubyonrails.com/contact;new" =~ Regexpert::Format::Url
43
+ # => 0
44
+ # >> "http://maps.google.co.uk/maps?f=q&q=the+london+eye&ie=UTF8&ll=51.503373,-0.11939&spn=0.007052,0.012767&z=16&iwloc=A" =~ Regexpert::Format::Url
45
+ # => 0
46
+ # >> "http://en.wikipedia.org/wiki/Sprite_(computer_graphics)" =~ Regexpert::Format::Url
47
+ # => 0
48
+ # TODO: think of a good example of a bad url
49
+ Url = begin
50
+ /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix
51
+ end
52
+
53
+ # This is taken from Django.Contrib.Localflavor.uk
54
+ # The regular expression used is sourced from the schema for British Standard
55
+ # BS7666 address types: http://www.govtalk.gov.uk/gdsc/schemas/bs7666-v2-0.xsd
56
+ #
57
+ # doctest: ukpostcode
58
+ # >> "GIR 0AA" =~ Regexpert::Format::UKPostcode # GIR 0AA is a special GIRO postcode
59
+ # => 0
60
+ # >> "AL40XB" =~ Regexpert::Format::UKPostcode
61
+ # => 0
62
+ # >> "CB4 1TL" =~ Regexpert::Format::UKPostcode
63
+ # => 0
64
+ #
65
+ # >> "AL44 NOP" =~ Regexpert::Format::UKPostcode
66
+ # => nil
67
+ # >> "CB4-1TL" =~ Regexpert::Format::UKPostcode
68
+ # => nil
69
+ #
70
+ UKPostcode = begin
71
+ outcode_pattern = '[A-PR-UWYZ]([0-9]{1,2}|([A-HIK-Y][0-9](|[0-9]|[ABEHMNPRVWXY]))|[0-9][A-HJKSTUW])'
72
+ incode_pattern = '[0-9][ABD-HJLNP-UW-Z]{2}'
73
+ postcode_regex = Regexp.new("^(GIR *0AA|#{outcode_pattern} *#{incode_pattern})$", Regexp::IGNORECASE)
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class RegexpertTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: regexpert
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matthew Rudy Jacobs
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-15 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Regular expressions bundled into a single place, so you dont have to
15
+ think anymore about what email regexp to use.
16
+ email: MatthewRudyJacobs@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - README
21
+ files:
22
+ - MIT-LICENSE
23
+ - Rakefile
24
+ - README
25
+ - test/regexpert_test.rb
26
+ - test/test_helper.rb
27
+ - lib/regexpert.rb
28
+ homepage: http://github.com/matthewrudy/regexpert
29
+ licenses: []
30
+ post_install_message:
31
+ rdoc_options:
32
+ - --main
33
+ - README
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 1.8.10
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: A bunch of useful Regular expressions
54
+ test_files: []