regxing 0.0.1.beta → 0.1.0.beta

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 557484a85293fcf105fbcd8a0260f94e5634bf14
4
- data.tar.gz: cb7dfc377c2cf54eb734b32707ce614a0b6e3d5b
3
+ metadata.gz: 03fcb84cf977a44564de7a3fb4486ce9a95f7b94
4
+ data.tar.gz: a928d6b809e73a711bc21686dfc6495ff20291f5
5
5
  SHA512:
6
- metadata.gz: d1ea90936572de005f950945797d95e4e2bc134613a8c05785edf56035e88ea63da99cd0226a91a5eddb390af73241498365b930170593cfaa7f5772c2928afc
7
- data.tar.gz: 0c5441853e89286bf757844a8e506672c187aba6645868c6cf28ee2d77dfda1c87f2ce8cce8944467bf55dca4c4d0ad07d241bd4645537132b6e02b342b30e00
6
+ metadata.gz: e26d4641ba668b5f2e3df03cfeba8933ffb9b5018030c7f570bd21bfc8568cb6766eab33f87ef535f386cdc0ef11f3115e03f0ba96d8d0aa4dad88cfb4910669
7
+ data.tar.gz: 71520aec022daf01ab38db47713196477539ae1f9af948ced5b36d1d2f0f1b1c26bdeec7c756428a2994920f1af9849949f816fce997246f8775549476a8ba17
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
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)
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/regexpert/badge.svg?branch=master)](https://coveralls.io/github/danascheider/regexpert?branch=master) [![Code Climate](https://codeclimate.com/github/danascheider/regexpert/badges/gpa.svg)](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
- # => 891-27-2800
11
+ generator.generate!
12
+ \# => 891-27-2800</code></pre>
@@ -7,11 +7,10 @@ module RegXing
7
7
  end
8
8
 
9
9
  def generate!
10
- expression = regex.to_s
11
10
  str = ""
12
11
 
13
12
  regex.split.each do |el|
14
- str << compile(el)
13
+ str << compile(el.first) * el.last
15
14
  end
16
15
 
17
16
  str
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
@@ -0,0 +1,8 @@
1
+ describe RegXing::Generator do
2
+ describe "less simple expressions" do
3
+ describe "given number of characters" do
4
+ let(:expression) { /\w{3}/ }
5
+ it_behaves_like "a matching string generator"
6
+ end
7
+ end
8
+ 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', '+', '\.', '\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', '{2,}' ]
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', '{,3}' ]
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', '{2,3}' ]
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', '{2}', '-', '2', '0', '1', '6' ]
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
@@ -1,5 +1,5 @@
1
1
  module RegXing
2
- VERSION = "0.0.1.beta"
2
+ VERSION = "0.1.0.beta"
3
3
 
4
4
  def self.version
5
5
  VERSION
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.1.beta
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.4.8
98
+ rubygems_version: 2.5.1
99
99
  signing_key:
100
100
  specification_version: 4
101
- summary: rambo-0.0.1.beta
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