class Regexgen::Trie
Attributes
alphabet[R]
root[R]
Public Class Methods
new()
click to toggle source
# File lib/regexgen/trie.rb, line 11 def initialize @alphabet = Set.new @root = State.new end
Public Instance Methods
add(str)
click to toggle source
# File lib/regexgen/trie.rb, line 16 def add(str) node = @root str.each_char do |char| @alphabet.add(char) node = node.transitions[char] end node.accepting = true end
add_all(strs)
click to toggle source
# File lib/regexgen/trie.rb, line 25 def add_all(strs) strs.each(&method(:add)) end
minimize()
click to toggle source
# File lib/regexgen/trie.rb, line 29 def minimize Regexgen.minimize(@root) end
to_regex(flags = nil)
click to toggle source
# File lib/regexgen/trie.rb, line 37 def to_regex(flags = nil) flags_i = 0 flags_i |= Regexp::EXTENDED if flags&.include?('x') flags_i |= Regexp::IGNORECASE if flags&.include?('i') flags_i |= Regexp::MULTILINE if flags&.include?('m') Regexp.new(to_s, flags_i) end
to_s()
click to toggle source
# File lib/regexgen/trie.rb, line 33 def to_s Regexgen.to_regex(minimize) end