caius-regex_concat 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Caius Durling
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,35 @@
1
+ # regex-concat
2
+
3
+ Extends the Regexp class with a concat method, which lets you concatenate any number of regular expression objects together.
4
+
5
+ If the regular expressions have any options (flags) set, then it adds together all the flags and sets the lot on the resulting regex.
6
+
7
+ ## Usage
8
+
9
+ require "rubygems"
10
+ require "regex_concat"
11
+
12
+ a = /foo/
13
+ b = /bar/m
14
+ c = /(sed)/i
15
+
16
+ Regexp.concat(a, b, c) # => /foobar(sed)/mi
17
+
18
+ ## Installation
19
+
20
+ $ gem install caius-regex_concat --source=http://gems.github.com/
21
+
22
+ ## Patches/Pull Requests
23
+
24
+ * Fork the project.
25
+ * Make your feature addition or bug fix.
26
+ * Add tests for it. This is important so I don't break it in a
27
+ future version unintentionally.
28
+ * Commit, do not mess with rakefile, version, or history.
29
+ (if you want to have your own version, that is fine but
30
+ bump version in a commit by itself I can ignore when I pull)
31
+ * Send me a pull request. Bonus points for topic branches.
32
+
33
+ ## License
34
+
35
+ Copyright (c) 2009 Caius Durling. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "regex_concat"
8
+ gem.summary = %Q{Concatenate regular expressions}
9
+ gem.description = %Q{Extends the Regexp class with a concat method, which lets you concatenate any number of regular expression objects together.}
10
+ gem.email = "dev@caius.name"
11
+ gem.homepage = "http://github.com/caius/regex_concat"
12
+ gem.authors = ["Caius Durling"]
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install technicalpickles-jeweler"
17
+ end
18
+
19
+ require 'spec/rake/spectask'
20
+ Spec::Rake::SpecTask.new(:spec) do |spec|
21
+ spec.libs << 'lib' << 'spec'
22
+ spec.spec_files = FileList['spec/**/*_spec.rb']
23
+ end
24
+
25
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.pattern = 'spec/**/*_spec.rb'
28
+ spec.rcov = true
29
+ end
30
+
31
+
32
+
33
+
34
+ task :default => :spec
35
+
36
+ require 'rake/rdoctask'
37
+ Rake::RDocTask.new do |rdoc|
38
+ if File.exist?('VERSION')
39
+ version = File.read('VERSION')
40
+ else
41
+ version = ""
42
+ end
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "regex_concat #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.1
@@ -0,0 +1,44 @@
1
+ module RegexpConcatenation
2
+ #
3
+ # Concatenates Regexp objects together into a new Regexp object.
4
+ # Keeps any flags, and adds them together. <tt>//i + //m == //im</tt>
5
+ #
6
+ # Regexp.concat(/foo/, /bar/) # => /foobar/
7
+ # Regexp.concat(/foo/i, /bar/) # => /foobar/i
8
+ # Regexp.concat(/foo/ix, /bar/m) # => /foobar/mix
9
+ #
10
+ def concat *regexes
11
+ # We need somewhere to store the flags from each regex
12
+ @flags = ""
13
+ # Run through the regexes in a map!
14
+ regexes.map! do |regex|
15
+ # Separate out the flags and the actual regex itself
16
+ flags, str = regex.to_s.scan(/(?:^\(\?(m?i?x?)-?m?i?x?:(.*?)\)$)/).first
17
+ # Add the flags to our store
18
+ @flags += flags
19
+ # And map this element to just the regex str
20
+ str
21
+ end
22
+ # Run through the flags, strip any duplicates
23
+ # and then convert them into the numerical counterpart
24
+ @flags = @flags.split("").uniq.inject(0) do |sum, flag|
25
+ sum += case flag
26
+ when "i"
27
+ 1
28
+ when "x"
29
+ 2
30
+ when "m"
31
+ 4
32
+ else
33
+ 0
34
+ end
35
+ end
36
+ # Get rid of the instance variable
37
+ f = @flags; @flags = nil;
38
+ # And return a Regexp object created from the regex strings
39
+ # complete with any flags we need specified.
40
+ Regexp.new(regexes.join(""), f)
41
+ end
42
+ end
43
+
44
+ Regexp.send(:extend, RegexpConcatenation)
@@ -0,0 +1,50 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
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{regex_concat}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Caius Durling"]
12
+ s.date = %q{2009-08-18}
13
+ s.description = %q{Extends the Regexp class with a concat method, which lets you concatenate any number of regular expression objects together.}
14
+ s.email = %q{dev@caius.name}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.md",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/regex_concat.rb",
27
+ "regex_concat.gemspec",
28
+ "spec/regex_concat_spec.rb",
29
+ "spec/spec_helper.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/caius/regex_concat}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.5}
35
+ s.summary = %q{Concatenate regular expressions}
36
+ s.test_files = [
37
+ "spec/regex_concat_spec.rb",
38
+ "spec/spec_helper.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ else
47
+ end
48
+ else
49
+ end
50
+ end
@@ -0,0 +1,53 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Regexp, "concat" do
4
+
5
+ it "should respond to the method" do
6
+ Regexp.should respond_to(:concat)
7
+ end
8
+
9
+ it "should concat two regexps" do
10
+ Regexp.concat(/foo/, /bar/).should == /foobar/
11
+ end
12
+
13
+ it "should concat three regexps" do
14
+ Regexp.concat(/foo/, /bar/, /sed/).should == /foobarsed/
15
+ end
16
+
17
+ 4.upto(10) do |i|
18
+ instance_eval <<-EOF
19
+ it "should concat #{i} regexps" do
20
+ regexps = []
21
+ #{i}.times {
22
+ regexps << /foo/
23
+ }
24
+ str = "foo" * #{i}
25
+
26
+ Regexp.concat(*regexps).should == /\#{str}/
27
+ end
28
+ EOF
29
+ end
30
+
31
+ it "should concat a lot of regexps" do
32
+ regexps = []
33
+ 5000.times {
34
+ regexps << /foo/
35
+ }
36
+ str = "foo" * 5000
37
+
38
+ Regexp.concat(*regexps).should == /#{str}/
39
+ end
40
+
41
+ describe "flags" do
42
+
43
+ it "should keep a flag on one of the regexes" do
44
+ Regexp.concat(/foo/i, /bar/).should == /foobar/i
45
+ end
46
+
47
+ it "should concat two flags on two of the regexes" do
48
+ Regexp.concat(/foo/i, /bar/m).should == /foobar/im
49
+ end
50
+
51
+ end
52
+
53
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'regex_concat'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+
8
+ Spec::Runner.configure do |config|
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: caius-regex_concat
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Caius Durling
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-18 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Extends the Regexp class with a concat method, which lets you concatenate any number of regular expression objects together.
17
+ email: dev@caius.name
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.md
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.md
30
+ - Rakefile
31
+ - VERSION
32
+ - lib/regex_concat.rb
33
+ - regex_concat.gemspec
34
+ - spec/regex_concat_spec.rb
35
+ - spec/spec_helper.rb
36
+ has_rdoc: false
37
+ homepage: http://github.com/caius/regex_concat
38
+ licenses:
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --charset=UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.3.5
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Concatenate regular expressions
63
+ test_files:
64
+ - spec/regex_concat_spec.rb
65
+ - spec/spec_helper.rb