regxing 0.0.1.beta → 0.1.0.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 +4 -4
- data/README.md +3 -2
- data/lib/regxing/generator.rb +1 -2
- data/lib/regxing/regex.rb +26 -1
- data/spec/lib/regxing/generator/less_simple_expression_spec.rb +8 -0
- data/spec/lib/regxing/regex_spec.rb +8 -8
- data/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03fcb84cf977a44564de7a3fb4486ce9a95f7b94
|
4
|
+
data.tar.gz: a928d6b809e73a711bc21686dfc6495ff20291f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e26d4641ba668b5f2e3df03cfeba8933ffb9b5018030c7f570bd21bfc8568cb6766eab33f87ef535f386cdc0ef11f3115e03f0ba96d8d0aa4dad88cfb4910669
|
7
|
+
data.tar.gz: 71520aec022daf01ab38db47713196477539ae1f9af948ced5b36d1d2f0f1b1c26bdeec7c756428a2994920f1af9849949f816fce997246f8775549476a8ba17
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# RegXing
|
2
|
-
[](https://travis-ci.org/danascheider/regxing) [](https://travis-ci.org/danascheider/regxing) [](https://coveralls.io/github/danascheider/regexpert?branch=master) [](https://codeclimate.com/github/danascheider/regexpert)
|
3
3
|
|
4
4
|
RegXing is a tool that takes regular expressions as input and returns strings matching them!
|
5
5
|
|
@@ -8,4 +8,5 @@ You can install RegXing using <pre><code>gem install regxing</code></pre>, or al
|
|
8
8
|
|
9
9
|
## Usage
|
10
10
|
<pre><code>generator = RegXing::Generator.new(/\d{3}-\d{2}-\d{4}/)
|
11
|
-
|
11
|
+
generator.generate!
|
12
|
+
\# => 891-27-2800</code></pre>
|
data/lib/regxing/generator.rb
CHANGED
data/lib/regxing/regex.rb
CHANGED
@@ -30,6 +30,21 @@ module RegXing
|
|
30
30
|
}
|
31
31
|
end
|
32
32
|
|
33
|
+
def count_indicators
|
34
|
+
[ /(?<!\\)\*/, /(?<!\\)\+/, /(?<!\\)\?/, /\{\d*\,?\d*\}/ ]
|
35
|
+
end
|
36
|
+
|
37
|
+
def process_count_indicator(indicator)
|
38
|
+
if indicator.match count_indicators.last
|
39
|
+
|
40
|
+
minimum = indicator.match(/(?<=\{)\d+/) ? indicator.match(/(?<=\{)\d+/)[0].to_i : 1
|
41
|
+
|
42
|
+
return minimum
|
43
|
+
else
|
44
|
+
return 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
33
48
|
private
|
34
49
|
|
35
50
|
def random_letter
|
@@ -80,7 +95,17 @@ module RegXing
|
|
80
95
|
end
|
81
96
|
|
82
97
|
def split
|
83
|
-
to_s.scan(/\\\?|[^\\]?\?|\\\.|[^\\]?\.|\\\+|[^\\]?\+|\\\*|[^\\]?\*|\\[a-zA-Z]|(?<!\\)[a-zA-Z]|\{\d*\,?\d*\}|\[\[\:.{5,6}\:\]\]|./).flatten
|
98
|
+
arr = to_s.scan(/\\\?|[^\\]?\?|\\\.|[^\\]?\.|\\\+|[^\\]?\+|\\\*|[^\\]?\*|\\[a-zA-Z]|(?<!\\)[a-zA-Z]|\{\d*\,?\d*\}|\[\[\:.{5,6}\:\]\]|./).flatten
|
99
|
+
|
100
|
+
arr.each_with_index do |item, index|
|
101
|
+
if RegXing::Regex.count_indicators.any? {|exp| arr[index + 1] && arr[index + 1].match(exp) }
|
102
|
+
arr[index] = [ item, RegXing::Regex.process_count_indicator(arr.delete_at(index + 1)) ]
|
103
|
+
else
|
104
|
+
arr[index] = [item, 1]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
arr
|
84
109
|
end
|
85
110
|
end
|
86
111
|
end
|
@@ -16,7 +16,7 @@ describe RegXing::Regex do
|
|
16
16
|
let(:exp) { described_class.new(/\d/) }
|
17
17
|
|
18
18
|
it "returns the expression as an array" do
|
19
|
-
expect(exp.split).to eql [ '\d' ]
|
19
|
+
expect(exp.split).to eql [[ '\d', 1 ]]
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -24,7 +24,7 @@ describe RegXing::Regex do
|
|
24
24
|
let(:exp) { described_class.new(/\d\w/) }
|
25
25
|
|
26
26
|
it "returns an array of character classes" do
|
27
|
-
expect(exp.split).to eql [ '\d', '\w' ]
|
27
|
+
expect(exp.split).to eql [ [ '\d', 1 ], [ '\w', 1 ] ]
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -32,7 +32,7 @@ describe RegXing::Regex do
|
|
32
32
|
let(:exp) { described_class.new(/.\d+/) }
|
33
33
|
|
34
34
|
it "handles the symbols properly" do
|
35
|
-
expect(exp.split).to eql [ '.', '\d',
|
35
|
+
expect(exp.split).to eql [ [ '.', 1 ], [ '\d', 1 ] ]
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -40,7 +40,7 @@ describe RegXing::Regex do
|
|
40
40
|
let(:exp) { described_class.new(/\d+\.\d+/) }
|
41
41
|
|
42
42
|
it "captures the escape" do
|
43
|
-
expect(exp.split).to eql [ '\d',
|
43
|
+
expect(exp.split).to eql [ [ '\d', 1 ], [ '\.', 1 ], [ '\d', 1 ] ]
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -49,7 +49,7 @@ describe RegXing::Regex do
|
|
49
49
|
let(:exp) { described_class.new(/\w{2,}/) }
|
50
50
|
|
51
51
|
it "captures the expression in the curly braces" do
|
52
|
-
expect(exp.split).to eql [ '\w',
|
52
|
+
expect(exp.split).to eql [ [ '\w', 2 ] ]
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -57,7 +57,7 @@ describe RegXing::Regex do
|
|
57
57
|
let(:exp) { described_class.new(/\w{,3}/) }
|
58
58
|
|
59
59
|
it "captures the expression in the curly braces" do
|
60
|
-
expect(exp.split).to eql [ '\w',
|
60
|
+
expect(exp.split).to eql [ [ '\w', 1 ] ]
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -65,7 +65,7 @@ describe RegXing::Regex do
|
|
65
65
|
let(:exp) { described_class.new(/\s{2,3}/) }
|
66
66
|
|
67
67
|
it "captures the expression in the curly braces" do
|
68
|
-
expect(exp.split).to eql [ '\s',
|
68
|
+
expect(exp.split).to eql [ [ '\s', 2 ] ]
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -73,7 +73,7 @@ describe RegXing::Regex do
|
|
73
73
|
let(:exp) { described_class.new(/Jan-\d{2}-2016/) }
|
74
74
|
|
75
75
|
it "captures the literals" do
|
76
|
-
expect(exp.split).to eql [ 'J', 'a', 'n', '-', '\d',
|
76
|
+
expect(exp.split).to eql [ [ 'J', 1 ], [ 'a', 1 ], [ 'n', 1 ], [ '-', 1 ], [ '\d', 2 ], [ '-', 1 ], [ '2', 1 ], [ '0', 1 ], [ '1', 1 ], [ '6', 1 ] ]
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
data/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: regxing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.1.0.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dana Scheider
|
@@ -95,10 +95,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
version: 1.3.1
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.
|
98
|
+
rubygems_version: 2.5.1
|
99
99
|
signing_key:
|
100
100
|
specification_version: 4
|
101
|
-
summary: rambo-0.0.
|
101
|
+
summary: rambo-0.1.0.beta
|
102
102
|
test_files:
|
103
103
|
- spec/lib/regxing/generator/less_simple_expression_spec.rb
|
104
104
|
- spec/lib/regxing/generator/simple_expression_spec.rb
|