Class: CriteriaOperator::GroupOperator

Inherits:
BaseOperator show all
Defined in:
lib/criteria_operator/group_operator.rb

Overview

Operator that groups multiple operators using one grouping type.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseOperator

deserialize, serialize, #serialize

Constructor Details

#initialize(operands = [], group_operator_type = GroupOperatorType::AND) ⇒ Void

The constructor for this operator. Expects a collection of operands and the operator type as parameters.

Parameters:

  • operands (Array<BaseOperator>) (defaults to: [])

    a collection of operands to group together

  • group_operator_type (GroupOperatorType) (defaults to: GroupOperatorType::AND)

    the type of this operator



26
27
28
29
# File 'lib/criteria_operator/group_operator.rb', line 26

def initialize(operands = [], group_operator_type = GroupOperatorType::AND)
  self.operand_collection = operands
  self.operator_type = group_operator_type
end

Instance Attribute Details

#operand_collectionArray<BaseOperator>

Returns the collection of operands grouped by this operator.

Returns:

  • (Array<BaseOperator>)

    the collection of operands grouped by this operator



20
21
22
# File 'lib/criteria_operator/group_operator.rb', line 20

def operand_collection
  @operand_collection
end

#operator_typeGroupOperatorType

Returns the type of this operator.

Returns:



17
18
19
# File 'lib/criteria_operator/group_operator.rb', line 17

def operator_type
  @operator_type
end

Instance Method Details

#cloneGroupOperator

Clones an operator with all sub-operators, creating a deep copy. Implementation of the abstract BaseOperator#clone.

Returns:



34
35
36
37
38
# File 'lib/criteria_operator/group_operator.rb', line 34

def clone
  ops = []
  self.operand_collection.each { |op| ops << clone_or_nil(op) }
  GroupOperator.new ops, self.operator_type
end