Class: RegXing::Regex
- Inherits:
-
Object
- Object
- RegXing::Regex
- Defined in:
- lib/regxing/regex.rb
Instance Attribute Summary collapse
-
#expression ⇒ Object
readonly
Instance Methods —————-.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(exp) ⇒ Regex
constructor
A new instance of Regex.
- #split ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(exp) ⇒ Regex
Returns a new instance of Regex.
89 90 91 |
# File 'lib/regxing/regex.rb', line 89 def initialize(exp) @expression = exp end |
Instance Attribute Details
#expression ⇒ Object (readonly)
Instance Methods
87 88 89 |
# File 'lib/regxing/regex.rb', line 87 def expression @expression end |
Class Method Details
.count_indicators ⇒ Object
33 34 35 |
# File 'lib/regxing/regex.rb', line 33 def count_indicators [ /(?<!\\)\*/, /(?<!\\)\+/, /(?<!\\)\?/, /\{\d*\,?\d*\}/ ] end |
.matchers ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/regxing/regex.rb', line 8 def matchers { /(?<!\\)\./ => random_letter, /\\d/ => random_number, /\\w/ => random_letter, /\\W/ => random_non_word_character, /\\D/ => random_letter, /\\h/ => random_hexdigit_character, /\\H/ => random_non_hexdigit_character, /\\s/ => " ", /\\S/ => random_letter, /\[\[\:alnum\:\]\]/ => random_letter, /\[\[\:alpha\:\]\]/ => random_letter, /\[\[\:digit\:\]\]/ => random_number, /\[\[\:graph\:\]\]/ => random_letter, /\[\[\:lower\:\]\]/ => random_lowercase_letter, /\[\[\:print\:\]\]/ => random_letter, /\[\[\:xdigit\:\]\]/ => random_hexdigit_character, /\[\[\:punct\:\]\]/ => random_non_word_character, /\[\[\:space\:\]\]/ => " ", /\[\[\:cntrl\:\]\]/ => "\a", /\[\[\:upper\:\]\]/ => random_uppercase_letter } end |
.process_count_indicator(indicator) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/regxing/regex.rb', line 37 def process_count_indicator(indicator) if indicator.match count_indicators.last minimum = indicator.match(/(?<=\{)\d+/) ? indicator.match(/(?<=\{)\d+/)[0].to_i : 1 return minimum else return 1 end end |
Instance Method Details
#split ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/regxing/regex.rb', line 97 def split arr = to_s.scan(/\\\?|[^\\]?\?|\\\.|[^\\]?\.|\\\+|[^\\]?\+|\\\*|[^\\]?\*|\\[a-zA-Z]|(?<!\\)[a-zA-Z]|\{\d*\,?\d*\}|\[\[\:.{5,6}\:\]\]|./).flatten arr.each_with_index do |item, index| if RegXing::Regex.count_indicators.any? {|exp| arr[index + 1] && arr[index + 1].match(exp) } arr[index] = [ item, RegXing::Regex.process_count_indicator(arr.delete_at(index + 1)) ] else arr[index] = [item, 1] end end arr end |
#to_s ⇒ Object
93 94 95 |
# File 'lib/regxing/regex.rb', line 93 def to_s expression.inspect[1..-2] end |