patternify 0.1.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rspec +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +75 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/patternify.rb +6 -0
- data/lib/patternify/or_clause.rb +21 -0
- data/lib/patternify/pattern.rb +52 -0
- data/lib/patternify/version.rb +3 -0
- data/patternify.gemspec +29 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6d173e39ae451b5e6ef70f28a8c20107a610055018891dc1a288680fe563924b
|
4
|
+
data.tar.gz: e25060a606205dab39b1427037e0d41d406a5b679f4b13369895888a9789b622
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2c12eac7aa13760a2770f71d77ad984d66a39a6b56bcad92432c2edc97bacd609cb76aa0b187d14708141aee1c566e630dafaa70ea29236e1c7d710b2fc62a31
|
7
|
+
data.tar.gz: 61738d7d04036e9aa145b3227734bb97e49cab16e81876846f4b6f3ecea92db3eacbf8efe150b6d32ce2b63115e5bd8f9a79095a16e87e5fab85cf8f8835195a
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
patternify (0.1.0.alpha1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.8.0)
|
12
|
+
rspec-core (~> 3.8.0)
|
13
|
+
rspec-expectations (~> 3.8.0)
|
14
|
+
rspec-mocks (~> 3.8.0)
|
15
|
+
rspec-core (3.8.0)
|
16
|
+
rspec-support (~> 3.8.0)
|
17
|
+
rspec-expectations (3.8.2)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.8.0)
|
20
|
+
rspec-mocks (3.8.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.8.0)
|
23
|
+
rspec-support (3.8.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.17)
|
30
|
+
patternify!
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.8)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.17.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Nils Sommer
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all 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,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/nsommer/patternify.svg?branch=master)](https://travis-ci.org/nsommer/patternify)
|
2
|
+
|
3
|
+
# Patternify
|
4
|
+
|
5
|
+
This ruby gem provides a DSL to describe patterns of regular expressions in a more human readable way.
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
pattern = Patternify::Pattern do
|
9
|
+
one_or_many do
|
10
|
+
any_char
|
11
|
+
end
|
12
|
+
|
13
|
+
string "@"
|
14
|
+
|
15
|
+
one_or_many do
|
16
|
+
negate do
|
17
|
+
string "."
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
string "."
|
22
|
+
|
23
|
+
either do
|
24
|
+
string "com"
|
25
|
+
or do
|
26
|
+
string "org"
|
27
|
+
or do
|
28
|
+
string "net"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
pattern.to_s
|
33
|
+
|
34
|
+
# => .+@[^\.]+.(com|org|net)
|
35
|
+
|
36
|
+
pattern.to_regexp.match?("john.doe@example.org")
|
37
|
+
|
38
|
+
# => true
|
39
|
+
```
|
40
|
+
|
41
|
+
**Note:** I started this gem for fun and it is highly incomplete and lacks validations and documentation. Pull requests are welcome.
|
42
|
+
|
43
|
+
## Installation
|
44
|
+
|
45
|
+
Add this line to your application's Gemfile:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
gem 'patternify'
|
49
|
+
```
|
50
|
+
|
51
|
+
And then execute:
|
52
|
+
|
53
|
+
$ bundle
|
54
|
+
|
55
|
+
Or install it yourself as:
|
56
|
+
|
57
|
+
$ gem install patternify
|
58
|
+
|
59
|
+
## Usage
|
60
|
+
|
61
|
+
TODO: Write usage instructions here
|
62
|
+
|
63
|
+
## Development
|
64
|
+
|
65
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
66
|
+
|
67
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nsommer/patternify.
|
72
|
+
|
73
|
+
## License
|
74
|
+
|
75
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "patternify"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/patternify.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Patternify
|
2
|
+
class OrClause
|
3
|
+
def initialize(&block)
|
4
|
+
self.conditions = []
|
5
|
+
self.or(&block)
|
6
|
+
end
|
7
|
+
|
8
|
+
def or(&block)
|
9
|
+
conditions << Patternify::Pattern.new(&block)
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
"(" + conditions.map(&:to_s).join("|") + ")"
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_accessor :conditions
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Patternify
|
2
|
+
class Pattern
|
3
|
+
def initialize(&block)
|
4
|
+
self.sub_patterns = []
|
5
|
+
self.instance_eval &block
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_regexp
|
9
|
+
Regexp.new(to_s)
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
sub_patterns.map(&:to_s).reduce(&:+)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_accessor :sub_patterns
|
19
|
+
|
20
|
+
def string(s)
|
21
|
+
sub_patterns << s
|
22
|
+
end
|
23
|
+
|
24
|
+
def none_or_one(&block)
|
25
|
+
sub_patterns << "["
|
26
|
+
self.instance_eval(&block)
|
27
|
+
sub_patterns << "]?"
|
28
|
+
end
|
29
|
+
|
30
|
+
def one_or_many(&block)
|
31
|
+
sub_patterns << "["
|
32
|
+
self.instance_eval(&block)
|
33
|
+
sub_patterns << "]+"
|
34
|
+
end
|
35
|
+
|
36
|
+
def none_or_many(&block)
|
37
|
+
sub_patterns << "["
|
38
|
+
self.instance_eval(&block)
|
39
|
+
sub_patterns << "]*"
|
40
|
+
end
|
41
|
+
|
42
|
+
def negate(&block)
|
43
|
+
sub_patterns << "[^"
|
44
|
+
self.instance_eval(&block)
|
45
|
+
sub_patterns << "]"
|
46
|
+
end
|
47
|
+
|
48
|
+
def any_char
|
49
|
+
sub_patterns << "."
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/patternify.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "patternify/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "patternify"
|
8
|
+
spec.version = Patternify::VERSION
|
9
|
+
spec.authors = ["Nils Sommer"]
|
10
|
+
spec.email = ["mail@nilssommer.de"]
|
11
|
+
|
12
|
+
spec.summary = %q{DSL for Regexp patterns}
|
13
|
+
spec.description = %q{Patternify provides a DSL optimized for readability to describe Regexp patterns.}
|
14
|
+
spec.homepage = "https://github.com/nsommer/patternify"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.8"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: patternify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.alpha1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nils Sommer
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.8'
|
55
|
+
description: Patternify provides a DSL optimized for readability to describe Regexp
|
56
|
+
patterns.
|
57
|
+
email:
|
58
|
+
- mail@nilssommer.de
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- lib/patternify.rb
|
74
|
+
- lib/patternify/or_clause.rb
|
75
|
+
- lib/patternify/pattern.rb
|
76
|
+
- lib/patternify/version.rb
|
77
|
+
- patternify.gemspec
|
78
|
+
homepage: https://github.com/nsommer/patternify
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 1.3.1
|
96
|
+
requirements: []
|
97
|
+
rubygems_version: 3.0.1
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: DSL for Regexp patterns
|
101
|
+
test_files: []
|