verbal_expressions 0.1.0 → 0.1.1
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.
- checksums.yaml +8 -8
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +63 -0
- data/LICENSE +20 -0
- data/README.md +72 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/verbal_expressions_spec.rb +68 -0
- metadata +75 -6
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDQwNTk5MTdlNmMyMmE5YTRlMTFmNDk1MjQ2Yzc5MGY4Zjg1NzVmZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDM1ZGM3ZmNhYzFhNzc4ZDg0YjdhY2M5MGMwMGU4NjNjYTk4NDFkNg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NmU0NDUxYjBjNGRkNzZhNDc0MzRmNWNiZjdlYWMyNmMyNTY4ZTVkYTJmMWNl
|
10
|
+
MmZkNDg4NjdkYTcxZDc4NWJmMDc0ZjM2OWZjODE1MjNjZjcwMDFiYWZmNTQ4
|
11
|
+
ZmNmYmZhMmVkMDhjYjZkZDcyM2NkZWZkOTZjOTU0YTA4ZWFhODI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjI3ZWY1MmVmZjM2NWY4MWFmMGY1NjNjZjIxMTM1MGUzMmFmZjk5NjUzZmEx
|
14
|
+
MzRiYzRjNjhiMjVkYWUzM2RlYjEwNzJhZWEzNTBlZTU4OTMzOWVlNDQzYjQw
|
15
|
+
ZTk3M2U4MzJiOTc3OWM1MDk4ODAxMzhiYWY1Y2U5ODVhOGU0OWU=
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
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 "rspec", "~> 2.14.0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 1.3.5"
|
12
|
+
gem "jeweler", "~> 1.8.4"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.3.5)
|
5
|
+
builder (3.2.2)
|
6
|
+
diff-lcs (1.2.4)
|
7
|
+
faraday (0.8.7)
|
8
|
+
multipart-post (~> 1.1)
|
9
|
+
git (1.2.5)
|
10
|
+
github_api (0.10.1)
|
11
|
+
addressable
|
12
|
+
faraday (~> 0.8.1)
|
13
|
+
hashie (>= 1.2)
|
14
|
+
multi_json (~> 1.4)
|
15
|
+
nokogiri (~> 1.5.2)
|
16
|
+
oauth2
|
17
|
+
hashie (2.0.5)
|
18
|
+
highline (1.6.19)
|
19
|
+
httpauth (0.2.0)
|
20
|
+
jeweler (1.8.6)
|
21
|
+
builder
|
22
|
+
bundler (~> 1.0)
|
23
|
+
git (>= 1.2.5)
|
24
|
+
github_api (= 0.10.1)
|
25
|
+
highline (>= 1.6.15)
|
26
|
+
nokogiri (= 1.5.10)
|
27
|
+
rake
|
28
|
+
rdoc
|
29
|
+
json (1.8.0)
|
30
|
+
jwt (0.1.8)
|
31
|
+
multi_json (>= 1.5)
|
32
|
+
multi_json (1.7.7)
|
33
|
+
multi_xml (0.5.4)
|
34
|
+
multipart-post (1.2.0)
|
35
|
+
nokogiri (1.5.10)
|
36
|
+
oauth2 (0.9.2)
|
37
|
+
faraday (~> 0.8)
|
38
|
+
httpauth (~> 0.2)
|
39
|
+
jwt (~> 0.1.4)
|
40
|
+
multi_json (~> 1.0)
|
41
|
+
multi_xml (~> 0.5)
|
42
|
+
rack (~> 1.2)
|
43
|
+
rack (1.5.2)
|
44
|
+
rake (10.1.0)
|
45
|
+
rdoc (3.12.2)
|
46
|
+
json (~> 1.4)
|
47
|
+
rspec (2.14.1)
|
48
|
+
rspec-core (~> 2.14.0)
|
49
|
+
rspec-expectations (~> 2.14.0)
|
50
|
+
rspec-mocks (~> 2.14.0)
|
51
|
+
rspec-core (2.14.4)
|
52
|
+
rspec-expectations (2.14.0)
|
53
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
54
|
+
rspec-mocks (2.14.1)
|
55
|
+
|
56
|
+
PLATFORMS
|
57
|
+
ruby
|
58
|
+
|
59
|
+
DEPENDENCIES
|
60
|
+
bundler (~> 1.3.5)
|
61
|
+
jeweler (~> 1.8.4)
|
62
|
+
rdoc (~> 3.12)
|
63
|
+
rspec (~> 2.14.0)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Ryan Endacott
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
VerbalExpressions.rb v0.1.0
|
2
|
+
=====================
|
3
|
+
|
4
|
+
## Ruby Regular Expressions made easy
|
5
|
+
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
|
+
## How to get started
|
8
|
+
|
9
|
+
Just install with `gem install verbal_expressions`, then require the library and you're good to go!
|
10
|
+
```ruby
|
11
|
+
require 'verbal_expressions'
|
12
|
+
```
|
13
|
+
|
14
|
+
## Examples
|
15
|
+
|
16
|
+
Here's a couple of simple examples to give an idea of how VerbalExpressions works:
|
17
|
+
|
18
|
+
### Testing if we have a valid URL
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
# Create an example of how to test for correctly formed URLs
|
22
|
+
tester = VerEx.new do
|
23
|
+
start_of_line
|
24
|
+
find 'http'
|
25
|
+
maybe 's'
|
26
|
+
find '://'
|
27
|
+
maybe 'www.'
|
28
|
+
anything_but ' '
|
29
|
+
end_of_line
|
30
|
+
end
|
31
|
+
|
32
|
+
# Create an example URL
|
33
|
+
test_url = "https://www.google.com"
|
34
|
+
|
35
|
+
# Use it just like a regular Ruby regex:
|
36
|
+
puts 'Hooray! It works!' if tester.match(test_url)
|
37
|
+
puts 'This works too!' if tester =~ test_url
|
38
|
+
|
39
|
+
# Print the generated regex:
|
40
|
+
puts tester.source # => /^(http)(s)?(\:\/\/)(www\.)?([^\ ]*)$/
|
41
|
+
```
|
42
|
+
|
43
|
+
### Replacing strings
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
# Create a test string
|
47
|
+
replace_me = "Replace bird with a duck"
|
48
|
+
|
49
|
+
# Create an expression that seeks for word "bird"
|
50
|
+
expression = VerEx.new { find 'bird' }
|
51
|
+
|
52
|
+
# Execute the expression like a normal Regexp object
|
53
|
+
result = replace_me.gsub( expression, "duck" );
|
54
|
+
|
55
|
+
puts result # Outputs "Replace duck with a duck"
|
56
|
+
```
|
57
|
+
|
58
|
+
## API documentation
|
59
|
+
|
60
|
+
I haven't added much documentation to this repo yet, but you can find the documentation for the original JavaScript repo on their [wiki](https://github.com/jehna/VerbalExpressions/wiki). Most of the methods have been ported as of v0.1.0 of the JavaScript repo. Just be sure to use the syntax explained above rather than the dot notation :)
|
61
|
+
|
62
|
+
## Contributions
|
63
|
+
Clone the repo and fork!
|
64
|
+
Pull requests are warmly welcomed!
|
65
|
+
|
66
|
+
## Issues
|
67
|
+
- I haven't yet ported the modifier code because Ruby Regexp handles modifiers a little differently.
|
68
|
+
- Because `or` is reserved in Ruby, `or` is currently aliased to `alternatively`. Unforunately, `then` is also reserved, so you must use `find` instead. I'm very open to better name ideas :)
|
69
|
+
|
70
|
+
## Thanks!
|
71
|
+
Thank you to @jehna for coming up with the awesome original idea!
|
72
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
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 = "verbal_expressions"
|
18
|
+
gem.homepage = "http://github.com/ryan-endacott/verbal_expressions"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Library that makes difficult regular expressions easy!}
|
21
|
+
gem.description = %Q{Verbal Expressions is a library that makes constructing difficult regular expressions simple and easy!}
|
22
|
+
gem.email = "rzeg24@gmail.com"
|
23
|
+
gem.authors = ["Ryan Endacott"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
task :default => :spec
|
35
|
+
|
36
|
+
require 'rdoc/task'
|
37
|
+
Rake::RDocTask.new do |rdoc|
|
38
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
39
|
+
|
40
|
+
rdoc.rdoc_dir = 'rdoc'
|
41
|
+
rdoc.title = "verbal_expressions #{version}"
|
42
|
+
rdoc.rdoc_files.include('README*')
|
43
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
44
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'verbal_expressions'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe VerEx do
|
4
|
+
|
5
|
+
describe '#find' do
|
6
|
+
|
7
|
+
let(:matcher) do
|
8
|
+
VerEx.new do
|
9
|
+
find 'lions'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should correctly build find regex' do
|
14
|
+
matcher.source.should == '(lions)'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should correctly match find' do
|
18
|
+
matcher.match('lions').should be_true
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should match part of a string with find' do
|
22
|
+
matcher.match('lions, tigers, and bears, oh my!').should be_true
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should only match the `find` part of a string' do
|
26
|
+
matcher.match('lions, tigers, and bears, oh my!')[0].should == 'lions'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'URL Regex Test' do
|
31
|
+
|
32
|
+
let(:matcher) do
|
33
|
+
VerEx.new do
|
34
|
+
start_of_line
|
35
|
+
find 'http'
|
36
|
+
maybe 's'
|
37
|
+
find '://'
|
38
|
+
maybe 'www.'
|
39
|
+
anything_but ' '
|
40
|
+
end_of_line
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'successfully builds regex for matching URLs' do
|
45
|
+
matcher.source.should == '^(http)(s)?(\:\/\/)(www\.)?([^\ ]*)$'
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'matches regular http URL' do
|
49
|
+
matcher.match('http://google.com').should be_true
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'matches https URL' do
|
53
|
+
matcher.match('https://google.com').should be_true
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'matches a URL with www' do
|
57
|
+
matcher.match('https://www.google.com').should be_true
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'fails to match when URL has a space' do
|
61
|
+
matcher.match('http://goo gle.com').should be_false
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'fails to match with htp:// is malformed' do
|
65
|
+
matcher.match('htp://google.com').should be_false
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
metadata
CHANGED
@@ -1,25 +1,94 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: verbal_expressions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
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-
|
12
|
-
dependencies:
|
11
|
+
date: 2013-07-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.14.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.14.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.3.5
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.3.5
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: jeweler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.8.4
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.8.4
|
13
69
|
description: Verbal Expressions is a library that makes constructing difficult regular
|
14
70
|
expressions simple and easy!
|
15
71
|
email: rzeg24@gmail.com
|
16
72
|
executables: []
|
17
73
|
extensions: []
|
18
|
-
extra_rdoc_files:
|
74
|
+
extra_rdoc_files:
|
75
|
+
- LICENSE
|
76
|
+
- README.md
|
19
77
|
files:
|
78
|
+
- .document
|
79
|
+
- .rspec
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- LICENSE
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- VERSION
|
20
86
|
- lib/verbal_expressions.rb
|
21
|
-
|
22
|
-
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
- spec/verbal_expressions_spec.rb
|
89
|
+
homepage: http://github.com/ryan-endacott/verbal_expressions
|
90
|
+
licenses:
|
91
|
+
- MIT
|
23
92
|
metadata: {}
|
24
93
|
post_install_message:
|
25
94
|
rdoc_options: []
|