verbal_expressions 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDQwNTk5MTdlNmMyMmE5YTRlMTFmNDk1MjQ2Yzc5MGY4Zjg1NzVmZQ==
4
+ OGQ5YmI1NTlhNGRmNzRmOTc4YzNkZWUzNDJhZGI0OGRlNDQ5NDA1MQ==
5
5
  data.tar.gz: !binary |-
6
- MDM1ZGM3ZmNhYzFhNzc4ZDg0YjdhY2M5MGMwMGU4NjNjYTk4NDFkNg==
6
+ ODVjNzM2YTUzMDI1YWQ0MDYwYjNmOWY2NWU2MDBhOGExYjZmYTFlNg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NmU0NDUxYjBjNGRkNzZhNDc0MzRmNWNiZjdlYWMyNmMyNTY4ZTVkYTJmMWNl
10
- MmZkNDg4NjdkYTcxZDc4NWJmMDc0ZjM2OWZjODE1MjNjZjcwMDFiYWZmNTQ4
11
- ZmNmYmZhMmVkMDhjYjZkZDcyM2NkZWZkOTZjOTU0YTA4ZWFhODI=
9
+ YmMzMGI2OWFmNDg5N2I4Yjc3Njc3MmIyYjdmNjcxNTIwOTQxYjI4NjRjMTgx
10
+ ZmFjNGJjMWE1NDAwYjM3OGQzNDk5MTE5NzdkMDM0YzkyM2FlMDJhODU4MzJm
11
+ ODE4OGIxNTBiNTZmNTlkMzcwN2M4YTY5NGZiYTAwNDhhOTM2MWY=
12
12
  data.tar.gz: !binary |-
13
- MjI3ZWY1MmVmZjM2NWY4MWFmMGY1NjNjZjIxMTM1MGUzMmFmZjk5NjUzZmEx
14
- MzRiYzRjNjhiMjVkYWUzM2RlYjEwNzJhZWEzNTBlZTU4OTMzOWVlNDQzYjQw
15
- ZTk3M2U4MzJiOTc3OWM1MDk4ODAxMzhiYWY1Y2U5ODVhOGU0OWU=
13
+ MjQzZDRlZjA1YWRmOTgxNzlmMWY0MzRmNGNiODIyYzg4MWM3MmY5ZmY5M2Q1
14
+ OWQ0M2FiNDlmNDY3YmVlMGIwOTAxM2RiODczYzAwN2RmZWJjMWVlYjAwYjRi
15
+ NWUyMzJjOGU5YWQ4Y2FlNzA1ZTA5ZDlhYjc2ZGE2ZWI0NmM0ZmY=
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
- VerbalExpressions.rb v0.1.0
1
+ verbal_expressions
2
2
  =====================
3
-
3
+ [![Build Status](https://travis-ci.org/ryan-endacott/verbal_expressions.png)](https://travis-ci.org/ryan-endacott/verbal_expressions)
4
+ [![Gem Version](https://badge.fury.io/rb/verbal_expressions.png)](http://badge.fury.io/rb/verbal_expressions)
4
5
  ## Ruby Regular Expressions made easy
5
6
  VerbalExpressions is a Ruby library that helps to construct difficult regular expressions - ported from the awesome JavaScript [VerbalExpressions](https://github.com/jehna/VerbalExpressions).
6
7
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -1,10 +1,10 @@
1
1
  # Ruby Verbal Expressions, based on the awesome JavaScript repo by @jehna: https://github.com/jehna/VerbalExpressions
2
2
 
3
- # For documentation and install instructions,
3
+ # For documentation and install instructions,
4
4
  # see the main Ruby repo: https://github.com/ryan-endacott/VerbalExpressions.rb
5
5
 
6
6
  class VerEx < Regexp
7
-
7
+
8
8
  def initialize(&block)
9
9
  @prefixes = ""
10
10
  @source = ""
@@ -14,11 +14,11 @@ class VerEx < Regexp
14
14
  instance_eval &block
15
15
  super(@prefixes + @source + @suffixes, @modifiers)
16
16
  end
17
-
17
+
18
18
  def method_missing(method, *args, &block)
19
19
  @self_before_instance_eval.send method, *args, &block
20
20
  end
21
-
21
+
22
22
  # We try to keep the syntax as
23
23
  # user-friendly as possible.
24
24
  # So we can use the "normal"
@@ -27,63 +27,63 @@ class VerEx < Regexp
27
27
  # TODO: then is reserved in ruby, so use find or think of a better name
28
28
  def find(value)
29
29
  value = sanitize(value)
30
- add("(#{value})")
30
+ add("(?:#{value})")
31
31
  end
32
-
32
+
33
33
  # start or end of line
34
-
34
+
35
35
  def start_of_line(enable = true)
36
36
  @prefixes = '^' if enable
37
37
  end
38
-
38
+
39
39
  def end_of_line(enable = true)
40
40
  @suffixes = '$' if enable
41
41
  end
42
-
42
+
43
43
  # Maybe is used to add values with ?
44
44
  def maybe(value)
45
45
  value = sanitize(value)
46
- add("(#{value})?")
46
+ add("(?:#{value})?")
47
47
  end
48
-
48
+
49
49
  # Any character any number of times
50
50
  def anything
51
- add("(.*)")
51
+ add("(?:.*)")
52
52
  end
53
53
 
54
54
  # Anything but these characters
55
55
  def anything_but(value)
56
56
  value = sanitize(value)
57
- add("([^#{value}]*)")
57
+ add("(?:[^#{value}]*)")
58
58
  end
59
59
 
60
60
  # Regular expression special chars
61
-
62
-
61
+
62
+
63
63
  def line_break
64
- add("(\\n|(\\r\\n))")
64
+ add('(?:\n|(?:\r\n))')
65
65
  end
66
-
66
+
67
67
  # And a shorthand for html-minded
68
68
  alias_method :br, :line_break
69
69
 
70
70
  def tab
71
- add("\\t")
71
+ add('\t')
72
72
  end
73
-
73
+
74
74
  # Any alphanumeric
75
75
  def word
76
- add("\\w+")
76
+ add('\w+')
77
77
  end
78
-
78
+
79
79
  # Any given character
80
80
  def any_of(value)
81
81
  value = sanitize(value)
82
82
  add("[#{value}]")
83
83
  end
84
-
84
+
85
85
  alias_method :any, :any_of
86
-
86
+
87
87
  # Usage: range( from, to [, from, to ... ] )
88
88
  def range(*args)
89
89
  value = "["
@@ -95,9 +95,9 @@ class VerEx < Regexp
95
95
  value += "]"
96
96
  add(value)
97
97
  end
98
-
98
+
99
99
  # Loops
100
-
100
+
101
101
  def multiple(value)
102
102
  value = sanitize(value)
103
103
  value += "+" unless ["+", "*"].include?(value.chars.first)
@@ -107,14 +107,30 @@ class VerEx < Regexp
107
107
  # Adds alternative expressions
108
108
  # TODO: or is a reserved keyword in ruby, think of better name
109
109
  def alternatively(value = nil)
110
- @prefixes += "(" unless @prefixes.include?("(")
110
+ @prefixes += "(?:" unless @prefixes.include?("(")
111
111
  @suffixes = ")" + @suffixes unless @suffixes.include?(")")
112
- add(")|(")
112
+ add(")|(?:")
113
113
  find(value) if value
114
114
  end
115
-
115
+
116
+
117
+ # Capture groups (can optionally name)
118
+ def begin_capture(name = nil)
119
+ if name
120
+ add("(?<#{name}>")
121
+ else
122
+ add("(")
123
+ end
124
+ end
125
+
126
+ def end_capture
127
+ add(")")
128
+ end
129
+
130
+
131
+
116
132
  private
117
-
133
+
118
134
  # Sanitation function for adding
119
135
  # anything safely to the expression
120
136
  def sanitize(value)
@@ -122,10 +138,10 @@ class VerEx < Regexp
122
138
  when Regexp, VerEx
123
139
  value.source
124
140
  else
125
- value.gsub(/([^\w])/) { "\\#{$1}" } # Escape non word chars
141
+ Regexp.quote(value)
126
142
  end
127
143
  end
128
-
144
+
129
145
  # Function to add stuff to the
130
146
  # expression. Also compiles the
131
147
  # new expression so it's ready to
@@ -133,5 +149,5 @@ class VerEx < Regexp
133
149
  def add(value = '')
134
150
  @source += value
135
151
  end
136
-
152
+
137
153
  end
data/spec/spec_helper.rb CHANGED
@@ -5,8 +5,8 @@ require 'verbal_expressions'
5
5
 
6
6
  # Requires supporting files with custom matchers and macros, etc,
7
7
  # in ./support/ and its subdirectories.
8
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
9
9
 
10
10
  RSpec.configure do |config|
11
-
11
+
12
12
  end
@@ -11,7 +11,7 @@ describe VerEx do
11
11
  end
12
12
 
13
13
  it 'should correctly build find regex' do
14
- matcher.source.should == '(lions)'
14
+ matcher.source.should == '(?:lions)'
15
15
  end
16
16
 
17
17
  it 'should correctly match find' do
@@ -42,7 +42,7 @@ describe VerEx do
42
42
  end
43
43
 
44
44
  it 'successfully builds regex for matching URLs' do
45
- matcher.source.should == '^(http)(s)?(\:\/\/)(www\.)?([^\ ]*)$'
45
+ matcher.source.should == '^(?:http)(?:s)?(?:://)(?:www\\.)?(?:[^\\ ]*)$'
46
46
  end
47
47
 
48
48
  it 'matches regular http URL' do
@@ -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 = "verbal_expressions"
8
+ s.version = "0.1.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ryan Endacott"]
12
+ s.date = "2013-07-30"
13
+ s.description = "Verbal Expressions is a library that makes constructing difficult regular expressions simple and easy!"
14
+ s.email = "rzeg24@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ ".travis.yml",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE",
26
+ "README.md",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/verbal_expressions.rb",
30
+ "spec/spec_helper.rb",
31
+ "spec/verbal_expressions_spec.rb",
32
+ "verbal_expressions.gemspec"
33
+ ]
34
+ s.homepage = "http://github.com/ryan-endacott/verbal_expressions"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "2.0.5"
38
+ s.summary = "Library that makes difficult regular expressions easy!"
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 4
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_development_dependency(%q<rspec>, ["~> 2.14.0"])
45
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
46
+ s.add_development_dependency(%q<bundler>, ["~> 1.3.5"])
47
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
48
+ else
49
+ s.add_dependency(%q<rspec>, ["~> 2.14.0"])
50
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
51
+ s.add_dependency(%q<bundler>, ["~> 1.3.5"])
52
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<rspec>, ["~> 2.14.0"])
56
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.3.5"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
59
+ end
60
+ end
61
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verbal_expressions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Endacott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-23 00:00:00.000000000 Z
11
+ date: 2013-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -77,6 +77,7 @@ extra_rdoc_files:
77
77
  files:
78
78
  - .document
79
79
  - .rspec
80
+ - .travis.yml
80
81
  - Gemfile
81
82
  - Gemfile.lock
82
83
  - LICENSE
@@ -86,6 +87,7 @@ files:
86
87
  - lib/verbal_expressions.rb
87
88
  - spec/spec_helper.rb
88
89
  - spec/verbal_expressions_spec.rb
90
+ - verbal_expressions.gemspec
89
91
  homepage: http://github.com/ryan-endacott/verbal_expressions
90
92
  licenses:
91
93
  - MIT