regex_generator 0.3.3 → 0.3.4
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 +1 -0
- data/bin/generate_regex +2 -1
- data/lib/regex_generator.rb +4 -0
- data/lib/regex_generator/generator.rb +6 -3
- data/lib/regex_generator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aba286d39cd71e85e8393e0aff3f9f4d1872650b4dad12063a7ce84d6d8b2966
|
4
|
+
data.tar.gz: e291cbac8deb7bcaca1889ed16740a424b711e9e150b2e9136401da2bd3ff608
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11f42b7a3e9043d23e99069f2d6cecf3611b1748f77acfa88c037ab621e4c319f73a958b084e87b3174eaa2732897bdf901e4c5cca096069bd09cf71eff219ee
|
7
|
+
data.tar.gz: 379e3baa608f1ae95c600114944b982c98bc3c5928ce6f408fb37a10ef66c6827aca06823a2804c0ec6a2476c221279e846b22d1c8e8e8f66fcf47c9c2122367
|
data/README.md
CHANGED
@@ -39,6 +39,7 @@ Allowed options:
|
|
39
39
|
- `:exact_target` - When it `true` regex will generated for exact target value
|
40
40
|
- `:self_recognition` - Symbols that will be represented as itself. Can be string or array
|
41
41
|
- `:look` - `:ahead` or `:behind` (`:behind` by default). To generate regex with text after or before the value
|
42
|
+
- `:strict_count` - When it `true` regex will generated with strict chars count
|
42
43
|
|
43
44
|
## Contributing
|
44
45
|
|
data/bin/generate_regex
CHANGED
@@ -23,13 +23,14 @@ OptionParser.new do |parser|
|
|
23
23
|
chars
|
24
24
|
end
|
25
25
|
|
26
|
+
parser.on('--strict_count', 'Generates regex with a strcit chars count')
|
26
27
|
parser.on('--exact_target', 'Generates regex with exact target value')
|
27
28
|
end.parse!(into: params)
|
28
29
|
|
29
30
|
unless ARGV.count.eql?(2)
|
30
31
|
error = ARGV.count < 2 ? 'target or text is missing' : "#{ARGV[2..-1].join(', ')}"
|
31
32
|
|
32
|
-
raise OptionParser::InvalidOption
|
33
|
+
raise OptionParser::InvalidOption, error
|
33
34
|
end
|
34
35
|
|
35
36
|
target, text = text_content(ARGV)
|
data/lib/regex_generator.rb
CHANGED
@@ -13,6 +13,10 @@ module RegexGenerator
|
|
13
13
|
# @param options [Hash] options to generate regex with
|
14
14
|
# @option options [true, false] :exact_target to generate regex
|
15
15
|
# with exact target value
|
16
|
+
# @option options [:ahead, :behind] :look to generate regex with text before
|
17
|
+
# or after the target
|
18
|
+
# @option options [true, false] :strict_count to generate regex with a strict
|
19
|
+
# chars count
|
16
20
|
# @return [Regexp]
|
17
21
|
#
|
18
22
|
# @example Generate regex
|
@@ -10,6 +10,8 @@ module RegexGenerator
|
|
10
10
|
# itself
|
11
11
|
# @option options [:ahead, :behind] :look to generate regex with text before
|
12
12
|
# or after the target
|
13
|
+
# @option options [true, false] :strict_count to generate regex with a
|
14
|
+
# strict chars count
|
13
15
|
def initialize(target, text, options = {})
|
14
16
|
@text = text
|
15
17
|
@target = RegexGenerator::Target.new(target)
|
@@ -69,11 +71,12 @@ module RegexGenerator
|
|
69
71
|
result
|
70
72
|
end
|
71
73
|
|
72
|
-
# Joins patterns by count, i.e. returns pattern with '+'
|
73
|
-
# with a multiple identical patterns
|
74
|
+
# Joins patterns by count, i.e. returns pattern with '+' (or chars count if
|
75
|
+
# :strict_count true) instead array with a multiple identical patterns
|
74
76
|
def join_patterns(array)
|
75
77
|
array.map do |patterns|
|
76
|
-
|
78
|
+
count = options[:strict_count] ? "{#{patterns.count}}" : '+'
|
79
|
+
patterns.one? ? patterns.first : "#{patterns.first}#{count}"
|
77
80
|
end.join
|
78
81
|
end
|
79
82
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: regex_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- o.vykhor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|