Module: MSFLVisitors::VisitorHelpers

Included in:
MSFLVisitors::Visitor::AggregationsVisitor, MSFLVisitors::Visitor::TermFilterVisitor
Defined in:
lib/msfl_visitors/visitor.rb

Instance Method Summary collapse

Instance Method Details

#composable_expr_for(regex_as_literal_string) ⇒ Object



19
20
21
# File 'lib/msfl_visitors/visitor.rb', line 19

def composable_expr_for(regex_as_literal_string)
  regex_as_literal_string[3..-4]
end

#escape_es_special_regex_chars(str) ⇒ Object

Note that the ES documentation also indicates that # is a special character that requires escaping and that this behavior is not part of the PERL regex; however Ruby automatically escapes literal hashes when constructing regices



8
9
10
# File 'lib/msfl_visitors/visitor.rb', line 8

def escape_es_special_regex_chars(str)
  str.gsub(/([@&<>~])/) { |m| "\\#{m}" }
end

#regex_escape(escaped_str) ⇒ Object



12
13
14
15
16
17
# File 'lib/msfl_visitors/visitor.rb', line 12

def regex_escape(escaped_str)
  esc = Regexp.escape("#{escaped_str.to_s}")
  exp = escape_es_special_regex_chars "#{esc}"
  # why you must use #inspect, not #to_s. @link http://ruby-doc.org/core-1.9.3/Regexp.html#method-i-3D-7E
  %r[.*#{exp}.*]
end