regeng 0.2.0d → 0.2.1d

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f6cf6723927902dc4b3bc8dca7d87226f3b0f87ec1cc6470cd0fc988931bdb8
4
- data.tar.gz: 4332481dc905c79166b87930e2132df9b220da8b85605162e56805084c070655
3
+ metadata.gz: dc48c96f2816dc74555db0375be84de43f4b90ce4b3d2fee735169a0356641b6
4
+ data.tar.gz: 00307c3d2c33780afe803fcf3869f87a7f0d02b37bafaf4d47a8d568b5a09228
5
5
  SHA512:
6
- metadata.gz: 42a4ab3bb1ef46eb1f010c3afeed40baf42e22d7dc9a9e35b09fc9d8b8af922898211bde6f944e8a02f40237eff794dfd5971a7352bd258e80d0017390066072
7
- data.tar.gz: c918cd089cadf976b29b34a6c94cf4299c94f2355f61fa096c639f2c721a737fe470774f121320348ba5c0d5cdceb8c5d7632ee662815825d1ee25bb9af43c51
6
+ metadata.gz: ad69acaec97a94da3bacbb836a6b72694b72deabdc0d8330543fe055016f85c3d5f44b99cb4a69e588328f5c87df3517215a4396fcbd2b44d6ac91a6c2966833
7
+ data.tar.gz: 6ff492642a080b6e54379dc92fb5ac1d9650e39f3698faf4af5f2f9a9eaab2b6887526c6086b9dacc717a83b819a5c6b516a8fcc183920f1a3f1e5bad188385c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- regeng (0.2.0d)
4
+ regeng (0.2.1d)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,3 +1,5 @@
1
+ [12-11-18][0.2.1d]: Dev Build: At modifiers and simple digit expressions.
2
+
1
3
  [12-10-18][0.2.0d]: Dev Build: Refactored gem, refactored character functionality.
2
4
 
3
5
  [12-09-18][0.1.1]: Fixed changelog link... oops.
@@ -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
- Regexp.new expression
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
- result = ''
27
- character_mod = ''
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 = '^' if /(except)/.match?(string)
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
- result = '[a-zA-Z]'
50
+ character_mod = 'a-zA-Z'
51
+ multiples = '+' if /(character)(s)/.match?(string)
45
52
  if /(uppercase)/.match?(string)
46
- result = '[A-Z]'
53
+ character_mod = 'A-Z'
47
54
  elsif /(lowercase)/.match?(string)
48
- result = '[a-z]'
55
+ character_mod = 'a-z'
49
56
  end
50
- result
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
@@ -1,3 +1,3 @@
1
1
  module Regeng
2
- VERSION = "0.2.0d"
2
+ VERSION = "0.2.1d"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regeng
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0d
4
+ version: 0.2.1d
5
5
  platform: ruby
6
6
  authors:
7
7
  - LucHighwalker