Class: Enumpath::Operator::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/enumpath/operator/base.rb

Overview

This class is abstract.

Subclass and override Base.detect? and #apply to implement a new path expression operator.

Abstract base class for Operator definitions. Provides some helper methods for each operator and defines the basic factory methods that must be implemented.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operator) ⇒ Base

Initializes an operator class with an operator string

Parameters:

  • operator (String)

    the the full, normalized operator



30
31
32
# File 'lib/enumpath/operator/base.rb', line 30

def initialize(operator)
  @operator = operator
end

Instance Attribute Details

#operatorString (readonly)

Returns the full, normalized operator.

Returns:

  • (String)

    the full, normalized operator



25
26
27
# File 'lib/enumpath/operator/base.rb', line 25

def operator
  @operator
end

Class Method Details

.detect?(operator, enum = nil) ⇒ true, false

This method is abstract.

Override in each path expression operator subclass

Provides an interface for determining if a given string represents the operator class

Parameters:

  • operator (String)

    the the full, normalized operator to test

  • enum (Enumerable) (defaults to: nil)

    an enum that can be used to assist in detection. Not all subclasses require an enum for detection.

Returns:

  • (true, false)

    whether the operator param appears to represent the operator class

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/enumpath/operator/base.rb', line 19

def detect?(operator, enum = nil)
  raise NotImplementedError
end

Instance Method Details

#apply(remaining_path, enum, resolved_path) {|remaining_path, enum, resolved_path| ... } ⇒ Object

This method is abstract.

Override in each path expression operator subclass

Provides an interface for applying the operator to a given enumerable and yielding that result back to the caller with updated arguments

Parameters:

  • remaining_path (Array)

    an array containing the normalized path segments yet to be resolved

  • enum (Enumerable)

    the object to apply the operator to

  • resolved_path (Array)

    an array containing the static path segments that have been resolved

Yields:

  • A block that will be called if the operator is applied successfully. If the operator cannot or should not be applied then the block is not yielded.

Yield Parameters:

  • remaining_path (Array)

    the new remaining_path after applying the operator

  • enum (Enumerable)

    the new enum after applying the operator

  • resolved_path (Array)

    the new resolved_path after applying the operator

Yield Returns:

  • (void)

Raises:

  • (NotImplementedError)


50
51
52
# File 'lib/enumpath/operator/base.rb', line 50

def apply(remaining_path, enum, resolved_path)
  raise NotImplementedError
end