regxing 0.0.1.beta

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 557484a85293fcf105fbcd8a0260f94e5634bf14
4
+ data.tar.gz: cb7dfc377c2cf54eb734b32707ce614a0b6e3d5b
5
+ SHA512:
6
+ metadata.gz: d1ea90936572de005f950945797d95e4e2bc134613a8c05785edf56035e88ea63da99cd0226a91a5eddb390af73241498365b930170593cfaa7f5772c2928afc
7
+ data.tar.gz: 0c5441853e89286bf757844a8e506672c187aba6645868c6cf28ee2d77dfda1c87f2ce8cce8944467bf55dca4c4d0ad07d241bd4645537132b6e02b342b30e00
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --format documentation --color --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ - 2.2.2
5
+ - 2.1.8
6
+ env:
7
+ - COVERAGE=true
8
+ sudo: false
9
+ branches:
10
+ only:
11
+ - master
12
+ notifications:
13
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Dana Scheider
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 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,
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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # RegXing
2
+ [![Build Status](https://travis-ci.org/danascheider/regxing.svg?branch=master)](https://travis-ci.org/danascheider/regxing) [![Coverage Status](https://coveralls.io/repos/github/danascheider/regxing/badge.svg?branch=master)](https://coveralls.io/github/danascheider/regxing?branch=master) [![Code Climate](https://codeclimate.com/github/danascheider/regxing/badges/gpa.svg)](https://codeclimate.com/github/danascheider/regxing)
3
+
4
+ RegXing is a tool that takes regular expressions as input and returns strings matching them!
5
+
6
+ ## Installation
7
+ You can install RegXing using <pre><code>gem install regxing</code></pre>, or alternatively, you can add to your project's Gemfile: <pre><code>gem "regxing", "~> 0.0.1"</code></pre>
8
+
9
+ ## Usage
10
+ <pre><code>generator = RegXing::Generator.new(/\d{3}-\d{2}-\d{4}/)
11
+ # => 891-27-2800
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "rspec/core/rake_task"
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task :default => [:spec]
@@ -0,0 +1,30 @@
1
+ module RegXing
2
+ class Generator
3
+ attr_accessor :regex
4
+
5
+ def initialize(regex)
6
+ @regex = RegXing::Regex.new(regex)
7
+ end
8
+
9
+ def generate!
10
+ expression = regex.to_s
11
+ str = ""
12
+
13
+ regex.split.each do |el|
14
+ str << compile(el)
15
+ end
16
+
17
+ str
18
+ end
19
+
20
+ private
21
+
22
+ def compile(el)
23
+ if expr = RegXing::Regex.matchers.find {|exp, val| el.match(exp) }
24
+ expr.last
25
+ else
26
+ el
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,86 @@
1
+ module RegXing
2
+ class Regex
3
+
4
+ # Class Methods
5
+ # -------------
6
+
7
+ class << self
8
+ def matchers
9
+ {
10
+ /(?<!\\)\./ => random_letter,
11
+ /\\d/ => random_number,
12
+ /\\w/ => random_letter,
13
+ /\\W/ => random_non_word_character,
14
+ /\\D/ => random_letter,
15
+ /\\h/ => random_hexdigit_character,
16
+ /\\H/ => random_non_hexdigit_character,
17
+ /\\s/ => " ",
18
+ /\\S/ => random_letter,
19
+ /\[\[\:alnum\:\]\]/ => random_letter,
20
+ /\[\[\:alpha\:\]\]/ => random_letter,
21
+ /\[\[\:digit\:\]\]/ => random_number,
22
+ /\[\[\:graph\:\]\]/ => random_letter,
23
+ /\[\[\:lower\:\]\]/ => random_lowercase_letter,
24
+ /\[\[\:print\:\]\]/ => random_letter,
25
+ /\[\[\:xdigit\:\]\]/ => random_hexdigit_character,
26
+ /\[\[\:punct\:\]\]/ => random_non_word_character,
27
+ /\[\[\:space\:\]\]/ => " ",
28
+ /\[\[\:cntrl\:\]\]/ => "\a",
29
+ /\[\[\:upper\:\]\]/ => random_uppercase_letter
30
+ }
31
+ end
32
+
33
+ private
34
+
35
+ def random_letter
36
+ ("a".."z").to_a.sample
37
+ end
38
+
39
+ alias_method :random_lowercase_letter, :random_letter
40
+
41
+ def random_uppercase_letter
42
+ ("A".."Z").to_a.sample
43
+ end
44
+
45
+ def random_number
46
+ (0..9).to_a.sample.to_s
47
+ end
48
+
49
+ def random_non_word_character
50
+ non_word_characters.sample
51
+ end
52
+
53
+ def random_hexdigit_character
54
+ [(0..9).to_a.map(&:to_s), ("A".."F").to_a, ("a".."f").to_a].flatten.sample
55
+ end
56
+
57
+ def random_non_hexdigit_character
58
+ ("h".."z").to_a.sample
59
+ end
60
+
61
+ def non_word_characters
62
+ [
63
+ "!", "@", "#", "%", "&", "*", "(", ")", "-", "{", "}",
64
+ "[", "]", "\\", "'", "\"", ":", ";", ",", ".", "?", "/"
65
+ ]
66
+ end
67
+ end
68
+
69
+ # Instance Methods
70
+ # ----------------
71
+
72
+ attr_reader :expression
73
+
74
+ def initialize(exp)
75
+ @expression = exp
76
+ end
77
+
78
+ def to_s
79
+ expression.inspect[1..-2]
80
+ end
81
+
82
+ def split
83
+ to_s.scan(/\\\?|[^\\]?\?|\\\.|[^\\]?\.|\\\+|[^\\]?\+|\\\*|[^\\]?\*|\\[a-zA-Z]|(?<!\\)[a-zA-Z]|\{\d*\,?\d*\}|\[\[\:.{5,6}\:\]\]|./).flatten
84
+ end
85
+ end
86
+ end
data/lib/regxing.rb ADDED
@@ -0,0 +1,2 @@
1
+ require_relative "./regxing/generator"
2
+ require_relative "./regxing/regex"
data/regxing.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require_relative "./version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "regxing"
6
+ s.version = RegXing.version
7
+ s.authors = ["Dana Scheider"]
8
+ s.description = "Regex in, string out"
9
+ s.summary = "rambo-#{s.version}"
10
+ s.email = "dana.scheider@gmail.com"
11
+ s.license = "MIT"
12
+ s.platform = Gem::Platform::RUBY
13
+ s.required_ruby_version = ">= 2.1.0"
14
+
15
+ s.add_development_dependency "rspec", "~> 3.3"
16
+ s.add_development_dependency "coveralls", "~> 0.7"
17
+ s.add_development_dependency "rake", "~> 10.4"
18
+
19
+ s.rubygems_version = ">= 1.6.1"
20
+ s.files = `git ls-files`.split("\n").reject {|path| path =~ /\.gitignore$/ }
21
+ s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
22
+ s.rdoc_options = ["--charset=UTF-8"]
23
+ s.require_path = "lib"
24
+ end
@@ -0,0 +1,126 @@
1
+ describe RegXing::Generator do
2
+ describe ".generate" do
3
+ context "any number of any characters" do
4
+ let(:expression) { /.*/ }
5
+ it_behaves_like "a matching string generator"
6
+ end
7
+
8
+ context "at least one character" do
9
+ let(:expression) { /.+/ }
10
+ it_behaves_like "a matching string generator"
11
+ end
12
+
13
+ context "character types" do
14
+ context "metacharacters" do
15
+ context "numbers" do
16
+ let(:expression) { /\d+/ }
17
+ it_behaves_like "a matching string generator"
18
+ end
19
+
20
+ context "word characters" do
21
+ let(:expression) { /\w+/ }
22
+ it_behaves_like "a matching string generator"
23
+ end
24
+
25
+ context "nonword characters" do
26
+ let(:expression) { /\W+/ }
27
+ it_behaves_like "a matching string generator"
28
+ end
29
+
30
+ context "non-numeric strings" do
31
+ let(:expression) { /\D+/ }
32
+ it_behaves_like "a matching string generator"
33
+ end
34
+
35
+ context "hexdigit characters" do
36
+ let(:expression) { /\h+/ }
37
+ it_behaves_like "a matching string generator"
38
+ end
39
+
40
+ context "non-hexdigit characters" do
41
+ let(:expression) { /\H+/ }
42
+ it_behaves_like "a matching string generator"
43
+ end
44
+
45
+ context "whitespace" do
46
+ let(:expression) { /\s+/ }
47
+ it_behaves_like "a matching string generator"
48
+ end
49
+
50
+ context "non-whitespace" do
51
+ let(:expression) { /\S+/ }
52
+ it_behaves_like "a matching string generator"
53
+ end
54
+ end
55
+
56
+ context "POSIX bracket expressions" do
57
+ context "alphanumeric" do
58
+ let(:expression) { /[[:alnum:]]/ }
59
+ it_behaves_like "a matching string generator"
60
+ end
61
+
62
+ context "letters" do
63
+ let(:expression) { /[[:alpha:]]/ }
64
+ it_behaves_like "a matching string generator"
65
+ end
66
+
67
+ context "numbers" do
68
+ let(:expression) { /[[:digit:]]/ }
69
+ it_behaves_like "a matching string generator"
70
+ end
71
+
72
+ context "non-blank characters" do
73
+ let(:expression) { /[[:graph:]]/ }
74
+ it_behaves_like "a matching string generator"
75
+ end
76
+
77
+ context "lowercase letters" do
78
+ let(:expression) { /[[:lower:]]/ }
79
+ it_behaves_like "a matching string generator"
80
+ end
81
+
82
+ context "uppercase letters" do
83
+ let(:expression) { /[[:upper:]]/ }
84
+ it_behaves_like "a matching string generator"
85
+ end
86
+
87
+ context "print character" do
88
+ let(:expression) { /[[:print:]]/ }
89
+ it_behaves_like "a matching string generator"
90
+ end
91
+
92
+ context "hexdigit characters" do
93
+ let(:expression) { /[[:xdigit:]]/ }
94
+ it_behaves_like "a matching string generator"
95
+ end
96
+
97
+ context "punctuation" do
98
+ let(:expression) { /[[:punct:]]/ }
99
+ it_behaves_like "a matching string generator"
100
+ end
101
+
102
+ context "whitespace" do
103
+ let(:expression) { /[[:space:]]/ }
104
+ it_behaves_like "a matching string generator"
105
+ end
106
+
107
+ context "control characters" do
108
+ let(:expression) { /[[:cntrl:]]/ }
109
+ it_behaves_like "a matching string generator"
110
+ end
111
+ end
112
+
113
+ context "literals" do
114
+ context "alphanumeric" do
115
+ let(:expression) { /a/ }
116
+ it_behaves_like "a matching string generator"
117
+ end
118
+ end
119
+ end
120
+
121
+ context "basic sequences" do
122
+ let(:expression) { /\d+.+/ }
123
+ it_behaves_like "a matching string generator"
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,81 @@
1
+ describe RegXing::Regex do
2
+ describe "#to_s" do
3
+ let(:exp) { described_class.new(/.*/) }
4
+
5
+ it "converts to a string" do
6
+ expect(exp.to_s).to be_a String
7
+ end
8
+
9
+ it "removes the slashes" do
10
+ expect(exp.to_s).to eql ".*"
11
+ end
12
+ end
13
+
14
+ describe "#split" do
15
+ context "basic case" do
16
+ let(:exp) { described_class.new(/\d/) }
17
+
18
+ it "returns the expression as an array" do
19
+ expect(exp.split).to eql [ '\d' ]
20
+ end
21
+ end
22
+
23
+ context "multiple items" do
24
+ let(:exp) { described_class.new(/\d\w/) }
25
+
26
+ it "returns an array of character classes" do
27
+ expect(exp.split).to eql [ '\d', '\w' ]
28
+ end
29
+ end
30
+
31
+ context "with symbols" do
32
+ let(:exp) { described_class.new(/.\d+/) }
33
+
34
+ it "handles the symbols properly" do
35
+ expect(exp.split).to eql [ '.', '\d', '+' ]
36
+ end
37
+ end
38
+
39
+ context "with escaped characters" do
40
+ let(:exp) { described_class.new(/\d+\.\d+/) }
41
+
42
+ it "captures the escape" do
43
+ expect(exp.split).to eql [ '\d', '+', '\.', '\d', '+' ]
44
+ end
45
+ end
46
+
47
+ context "with ranges" do
48
+ context "with minimum" do
49
+ let(:exp) { described_class.new(/\w{2,}/) }
50
+
51
+ it "captures the expression in the curly braces" do
52
+ expect(exp.split).to eql [ '\w', '{2,}' ]
53
+ end
54
+ end
55
+
56
+ context "with maximum" do
57
+ let(:exp) { described_class.new(/\w{,3}/) }
58
+
59
+ it "captures the expression in the curly braces" do
60
+ expect(exp.split).to eql [ '\w', '{,3}' ]
61
+ end
62
+ end
63
+
64
+ context "with minimum and maximum" do
65
+ let(:exp) { described_class.new(/\s{2,3}/) }
66
+
67
+ it "captures the expression in the curly braces" do
68
+ expect(exp.split).to eql [ '\s', '{2,3}' ]
69
+ end
70
+ end
71
+
72
+ context "with literals" do
73
+ let(:exp) { described_class.new(/Jan-\d{2}-2016/) }
74
+
75
+ it "captures the literals" do
76
+ expect(exp.split).to eql [ 'J', 'a', 'n', '-', '\d', '{2}', '-', '2', '0', '1', '6' ]
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,10 @@
1
+ require "coveralls"
2
+
3
+ Coveralls.wear! if ENV["COVERAGE"] == "true"
4
+
5
+ require "rspec"
6
+ require "rspec/expectations"
7
+ require "rspec/mocks"
8
+
9
+ require_relative "./support/shared_examples/matching_string_generator"
10
+ require_relative "../lib/regxing"
@@ -0,0 +1,6 @@
1
+ shared_examples "a matching string generator" do
2
+ it "generates a matching string" do
3
+ generator = RegXing::Generator.new(expression)
4
+ expect(generator.generate!).to match expression
5
+ end
6
+ end
data/version.rb ADDED
@@ -0,0 +1,7 @@
1
+ module RegXing
2
+ VERSION = "0.0.1.beta"
3
+
4
+ def self.version
5
+ VERSION
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: regxing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.beta
5
+ platform: ruby
6
+ authors:
7
+ - Dana Scheider
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-19 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: '3.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.4'
55
+ description: Regex in, string out
56
+ email: dana.scheider@gmail.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - ".rspec"
62
+ - ".travis.yml"
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.md
66
+ - Rakefile
67
+ - lib/regxing.rb
68
+ - lib/regxing/generator.rb
69
+ - lib/regxing/regex.rb
70
+ - regxing.gemspec
71
+ - spec/lib/regxing/generator/less_simple_expression_spec.rb
72
+ - spec/lib/regxing/generator/simple_expression_spec.rb
73
+ - spec/lib/regxing/regex_spec.rb
74
+ - spec/spec_helper.rb
75
+ - spec/support/shared_examples/matching_string_generator.rb
76
+ - version.rb
77
+ homepage:
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options:
83
+ - "--charset=UTF-8"
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 2.1.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
+ rubyforge_project:
98
+ rubygems_version: 2.4.8
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: rambo-0.0.1.beta
102
+ test_files:
103
+ - spec/lib/regxing/generator/less_simple_expression_spec.rb
104
+ - spec/lib/regxing/generator/simple_expression_spec.rb
105
+ - spec/lib/regxing/regex_spec.rb
106
+ - spec/spec_helper.rb
107
+ - spec/support/shared_examples/matching_string_generator.rb