module Enumpath::Operator

Namespace for classes that represent path expression operators

Constants

ROOT

Public Class Methods

detect(operator, enum) click to toggle source

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

@param operator [String] the operator to infer type on @param enum [Enumerable] the enumerable to assist in detecting child operators @return an instance of a subclass of Enumpath::Operator based on what was detected, or nil if nothing was

detected
# 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

Private Class Methods

child?(operator, enum) click to toggle source
# File lib/enumpath/operator.rb, line 39
def child?(operator, enum)
  Enumpath::Operator::Child.detect?(operator, enum)
end
filter_expression?(operator) click to toggle source
# File lib/enumpath/operator.rb, line 59
def filter_expression?(operator)
  Enumpath::Operator::FilterExpression.detect?(operator)
end
operator(operator_class, operator) click to toggle source
# File lib/enumpath/operator.rb, line 67
def operator(operator_class, operator)
  Enumpath.log("#{operator_class} operator detected")
  klass = Object.const_get("Enumpath::Operator::#{operator_class}")
  klass.new(operator)
end
recursive_descent?(operator) click to toggle source
# File lib/enumpath/operator.rb, line 47
def recursive_descent?(operator)
  Enumpath::Operator::RecursiveDescent.detect?(operator)
end
slice?(operator) click to toggle source
# File lib/enumpath/operator.rb, line 63
def slice?(operator)
  Enumpath::Operator::Slice.detect?(operator)
end
subscript_expression?(operator) click to toggle source
# File lib/enumpath/operator.rb, line 55
def subscript_expression?(operator)
  Enumpath::Operator::SubscriptExpression.detect?(operator)
end
union?(operator) click to toggle source
# File lib/enumpath/operator.rb, line 51
def union?(operator)
  Enumpath::Operator::Union.detect?(operator)
end
wildcard?(operator) click to toggle source
# File lib/enumpath/operator.rb, line 43
def wildcard?(operator)
  Enumpath::Operator::Wildcard.detect?(operator)
end