Module: Enumpath::Operator

Defined in:
lib/enumpath/operator.rb,
lib/enumpath/operator/base.rb,
lib/enumpath/operator/child.rb,
lib/enumpath/operator/slice.rb,
lib/enumpath/operator/union.rb,
lib/enumpath/operator/wildcard.rb,
lib/enumpath/operator/filter_expression.rb,
lib/enumpath/operator/recursive_descent.rb,
lib/enumpath/operator/subscript_expression.rb

Overview

Namespace for classes that represent path expression operators

Defined Under Namespace

Classes: Base, Child, FilterExpression, RecursiveDescent, Slice, SubscriptExpression, Union, Wildcard

Constant Summary collapse

ROOT =
'$'

Class Method Summary collapse

Class Method Details

.detect(operator, enum) ⇒ Object

Infer the type of operator and return an instance of its Enumpath::Operator subclass

Parameters:

  • operator (String)

    the operator to infer type on

  • enum (Enumerable)

    the enumerable to assist in detecting child operators

Returns:

  • an instance of a subclass of Enumpath::Operator based on what was detected, or nil if nothing was detected



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/enumpath/operator.rb', line 24

def detect(operator, enum) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
  return operator(:Child, operator) if child?(operator, enum)
  return operator(:Wildcard, operator) if wildcard?(operator)
  return operator(:RecursiveDescent, operator) if recursive_descent?(operator)
  return operator(:Union, operator) if union?(operator)
  return operator(:SubscriptExpression, operator) if subscript_expression?(operator)
  return operator(:FilterExpression, operator) if filter_expression?(operator)
  return operator(:Slice, operator) if slice?(operator)

  Enumpath.log('Not a valid operator for enum')
  nil
end