Class: ChewyQuery::Builder::Nodes::Regexp
- Defined in:
- lib/chewy_query/builder/nodes/regexp.rb
Constant Summary collapse
- FLAGS =
%w(all anystring automaton complement empty intersection interval none)
Instance Method Summary collapse
- #__render__ ⇒ Object
-
#initialize(name, regexp, *args) ⇒ Regexp
constructor
A new instance of Regexp.
Methods inherited from Expr
Methods inherited from Base
Constructor Details
#initialize(name, regexp, *args) ⇒ Regexp
Returns a new instance of Regexp.
7 8 9 10 11 12 13 14 15 |
# File 'lib/chewy_query/builder/nodes/regexp.rb', line 7 def initialize(name, regexp, *args) @name = name.to_s @regexp = regexp.respond_to?(:source) ? regexp.source : regexp.to_s @options = args. if args.any? || @options[:flags].present? @options[:flags] = FLAGS & (args.any? ? args.flatten : @options[:flags]).map(&:to_s).map(&:downcase) end end |
Instance Method Details
#__render__ ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/chewy_query/builder/nodes/regexp.rb', line 17 def __render__ body = @options[:flags] ? { value: @regexp, flags: @options[:flags].map(&:to_s).map(&:upcase).uniq.join('|') } : @regexp filter = { @name => body } if @options.key?(:cache) filter[:_cache] = !!@options[:cache] filter[:_cache_key] = @options[:cache].is_a?(TrueClass) || @options[:cache].is_a?(FalseClass) ? @regexp.underscore : @options[:cache] end { regexp: filter } end |