Class: RandallRegExp::CharClass
- Inherits:
-
Treetop::Runtime::SyntaxNode
- Object
- Treetop::Runtime::SyntaxNode
- RandallRegExp::CharClass
- Includes:
- CharSets
- Defined in:
- lib/randall/charclass.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#chars ⇒ Object
‘[’ neg:‘^’? comp:(cc_comp / char_class)+ amps:(‘&&’ char_class)? ‘]’.
- #rand ⇒ Object
Methods included from CharSets
#all_chars, #control, #decimal_number, #graph, #letter, #lower_letter, #punctuation, #space, #strseq, #upper_letter, #word, #xchar, #xdigit
Instance Method Details
#chars ⇒ Object
‘[’ neg:‘^’? comp:(cc_comp / char_class)+ amps:(‘&&’ char_class)? ‘]’
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/randall/charclass.rb', line 83 def chars return @chars if @chars # build charset @chars = comp.elements.map(&:chars).reduce([], :+).uniq @chars &= amps.elements[1].chars unless amps.empty? @chars = self.all_chars - @chars unless neg.empty? @chars end |
#rand ⇒ Object
94 95 96 97 |
# File 'lib/randall/charclass.rb', line 94 def rand self.chars @chars.empty? ? '' : @chars[Kernel.rand(@chars.size)] end |