regeng 0.2.0d → 0.2.1d
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/changelog.md +2 -0
- data/lib/regeng.rb +54 -15
- data/lib/regeng/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc48c96f2816dc74555db0375be84de43f4b90ce4b3d2fee735169a0356641b6
|
4
|
+
data.tar.gz: 00307c3d2c33780afe803fcf3869f87a7f0d02b37bafaf4d47a8d568b5a09228
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad69acaec97a94da3bacbb836a6b72694b72deabdc0d8330543fe055016f85c3d5f44b99cb4a69e588328f5c87df3517215a4396fcbd2b44d6ac91a6c2966833
|
7
|
+
data.tar.gz: 6ff492642a080b6e54379dc92fb5ac1d9650e39f3698faf4af5f2f9a9eaab2b6887526c6086b9dacc717a83b819a5c6b516a8fcc183920f1a3f1e5bad188385c
|
data/Gemfile.lock
CHANGED
data/changelog.md
CHANGED
data/lib/regeng.rb
CHANGED
@@ -6,26 +6,34 @@ require 'regeng/version'
|
|
6
6
|
module Regeng
|
7
7
|
class Error < StandardError; end
|
8
8
|
|
9
|
-
CHARACTER_COND = /(any character(s)?( except)?( between)?( [a-zA-Z])+((-)|( through )|( to )|( and )){1}[a-zA-Z]){1}/.freeze
|
10
|
-
CHARACTER_SIMP = /(any ((uppercase )?|(lowercase )?)character){1}/.freeze
|
9
|
+
CHARACTER_COND = /((any )?(character)(s)?( except)?( between)?( [a-zA-Z])+((-)|( through )|( to )|( and )){1}[a-zA-Z]){1}/.freeze
|
10
|
+
CHARACTER_SIMP = /((any )?((uppercase )?|(lowercase )?)(character)(s)?){1}/.freeze
|
11
|
+
|
12
|
+
DIGIT_COND = /((any )?((digit)|(number))(s)?( except)?( between)?( [0-9])+((-)|( through )|( to )|( and )){1}[0-9]){1}/.freeze
|
13
|
+
DIGIT_SIMPLE = /(any ((digit)|(number))){1}/.freeze
|
14
|
+
|
15
|
+
AT_COND = /( at )((start)|(end))( of )((line)|(string))/.freeze
|
11
16
|
|
12
17
|
def self.expression(string)
|
13
18
|
expression = ''
|
14
19
|
if CHARACTER_COND.match?(string)
|
15
|
-
puts string.match(CHARACTER_COND)
|
16
20
|
expression = characters_condition(string)
|
17
21
|
elsif CHARACTER_SIMP.match?(string)
|
18
|
-
puts string.match(CHARACTER_SIMP)
|
19
22
|
expression = characters_simple(string)
|
23
|
+
elsif DIGIT_COND.match?(string)
|
24
|
+
expression = digit_condition(string)
|
25
|
+
elsif DIGIT_SIMPLE.match?(string)
|
26
|
+
expression = digit_simple(string)
|
20
27
|
end
|
21
28
|
|
22
|
-
|
29
|
+
at_mod = at_condition(string) if AT_COND.match?(string)
|
30
|
+
|
31
|
+
Regexp.new "#{at_mod}#{expression}"
|
23
32
|
end
|
24
33
|
|
25
34
|
def self.characters_condition(string)
|
26
|
-
|
27
|
-
|
28
|
-
except = ''
|
35
|
+
except = '^' if /(except)/.match?(string)
|
36
|
+
multiples = '+' if /(character)(s)/.match?(string)
|
29
37
|
if /( ([a-z])(-)(([a-z])))/i.match?(string)
|
30
38
|
character_mod = string.match(/([a-z]-[a-z])/i)
|
31
39
|
elsif /( ([a-z])(( through )|( to ))(([a-z])))/i.match?(string)
|
@@ -35,18 +43,49 @@ module Regeng
|
|
35
43
|
unfiltered_mod = string.match(/( ([a-z] )+(and )([a-z]))/)
|
36
44
|
character_mod = unfiltered_mod.to_s.gsub(/( )|(and )/, '')
|
37
45
|
end
|
38
|
-
except
|
39
|
-
result = "#{result}[#{except}#{character_mod}]" if character_mod != ''
|
40
|
-
result
|
46
|
+
"[#{except}#{character_mod}]#{multiples}"
|
41
47
|
end
|
42
48
|
|
43
49
|
def self.characters_simple(string)
|
44
|
-
|
50
|
+
character_mod = 'a-zA-Z'
|
51
|
+
multiples = '+' if /(character)(s)/.match?(string)
|
45
52
|
if /(uppercase)/.match?(string)
|
46
|
-
|
53
|
+
character_mod = 'A-Z'
|
47
54
|
elsif /(lowercase)/.match?(string)
|
48
|
-
|
55
|
+
character_mod = 'a-z'
|
49
56
|
end
|
50
|
-
|
57
|
+
"[#{character_mod}]#{multiples}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.digit_condition(string)
|
61
|
+
except = '^' if /(except)/.match?(string)
|
62
|
+
multiples = '+' if /((digit)|(number))(s)/.match?(string)
|
63
|
+
if /( ([0-9])(-)(([0-9])))/.match?(string)
|
64
|
+
digit_mod = string.match(/([0-9]-[0-9])/)
|
65
|
+
elsif /( ([0-9])(( through )|( to ))(([0-9])))/i.match?(string)
|
66
|
+
unfiltered_mod = string.match(/(([0-9])(( through )|( to ))(([0-9])))/)
|
67
|
+
digit_mod = unfiltered_mod.to_s.sub(/( through )|( to )/, '-')
|
68
|
+
elsif /((between) ([0-9])( and )([0-9]))/.match?(string)
|
69
|
+
unfiltered_mod = string.match(/(([0-9])( and )([0-9]))/)
|
70
|
+
digit_mod = unfiltered_mod.to_s.sub(/( and )/, '-')
|
71
|
+
# elsif /( ([a-z] )+(and )([a-z]))/.match?(string)
|
72
|
+
# unfiltered_mod = string.match(/( ([a-z] )+(and )([a-z]))/)
|
73
|
+
# digit_mod = unfiltered_mod.to_s.gsub(/( )|(and )/, '')
|
74
|
+
end
|
75
|
+
"[#{except}#{digit_mod}]#{multiples}"
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.digit_simple(string)
|
79
|
+
digit_mod = '0-9'
|
80
|
+
multiples = '+' if /((digit)|(number))(s)/.match?(string)
|
81
|
+
"[#{digit_mod}]#{multiples}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.at_condition(string)
|
85
|
+
at_mod = '^' if /(start of line)/.match?(string)
|
86
|
+
at_mod = '$' if /(end of line)/.match?(string)
|
87
|
+
at_mod = '\A' if /(start of string)/.match?(string)
|
88
|
+
at_mod = '\z' if /(end of string)/.match?(string)
|
89
|
+
at_mod
|
51
90
|
end
|
52
91
|
end
|
data/lib/regeng/version.rb
CHANGED