Class: DDQL::Operators

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/ddql/operators.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOperators

Returns a new instance of Operators.



33
34
35
# File 'lib/ddql/operators.rb', line 33

def initialize
  @cache = build_cache
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



15
16
17
# File 'lib/ddql/operators.rb', line 15

def cache
  @cache
end

Class Method Details

.float_map_opsObject



17
18
19
# File 'lib/ddql/operators.rb', line 17

def self.float_map_ops
  instance.cache.select { |_, v| v.is_a? InfixFloatMapOperator }
end

.operator_regex(operator_type) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ddql/operators.rb', line 21

def self.operator_regex(operator_type)
  ops = instance.cache.select { |k, v| v.type?(operator_type) }
  
  if ops.empty?
    # if there are no registered operators of the given type use negative
    # lookahead to generate a regex pattern that can never be matched
    return /(?!x)x/
  else
    ops.keys[1..-1].inject(ops.keys.first) { |a, e| Regexp.union(a, ops[e].pattern) }
  end
end