module SublimeDSL::Tools::Helpers

Helper methods to include in DSL blocks as needed.

Public Class Methods

optimized_re(words) click to toggle source

Return an optimized regexp string matching a word in words. Example:

include SublimeDSL::Tools::Helpers
list = %w(abs addr addrlong airy allcomb allperm anyalnum anyalpha anycntrl)
optimized_re(list)
  => 'a(bs|ddr(long)?|iry|ll(comb|perm)|ny(al(num|pha)|cntrl))'
# File lib/sublime_dsl/tools/helpers.rb, line 16
def optimized_re(words)
  root = Node.new('')
  root.add_children words
  root.reduce!
  root.to_re
end

Private Instance Methods

optimized_re(words) click to toggle source

Return an optimized regexp string matching a word in words. Example:

include SublimeDSL::Tools::Helpers
list = %w(abs addr addrlong airy allcomb allperm anyalnum anyalpha anycntrl)
optimized_re(list)
  => 'a(bs|ddr(long)?|iry|ll(comb|perm)|ny(al(num|pha)|cntrl))'
# File lib/sublime_dsl/tools/helpers.rb, line 16
def optimized_re(words)
  root = Node.new('')
  root.add_children words
  root.reduce!
  root.to_re
end