class OnappMarket::API::Query::MonoOperator

Base class for an operator which operates on a single leaf e.g. NOT

Public Class Methods

new(operator, node) click to toggle source

Initiase the operator

Attributes

  • operator - Textual name of operator (for serialisation help)

  • node - The node this operator is operating on, can be a Comparator or another Operator

# File lib/onapp_market/api/query/operators.rb, line 57
def initialize(operator, node)
  # Check type
  raise "#{node} - not a valid node for a MonoOperator" if !(node.is_a?(Comparator) || node.is_a?(Operator))
  @operator = operator
  super([node])
end

Public Instance Methods

flatten() { |self| ... } click to toggle source

Flatten this operator and children as per a regular expression.

Yields each element of the flattened experssion

i.e. Operator -> OpenParenthese -> Node -> CloseParenthese

# File lib/onapp_market/api/query/operators.rb, line 70
def flatten
  # Operator e.g. NOT
  yield self
  # Helper for precedence
  yield OpenParenthese.new
  # The node 
  yield self.leaves.first
  # Helper for precedence
  yield CloseParenthese.new
end
to_hash() click to toggle source
# File lib/onapp_market/api/query/operators.rb, line 87
def to_hash
  {"type" => "MonoOperator", "operator" => @operator, "leaves" => @leaves.map { |l| l.to_hash }  }
end
to_s() click to toggle source

Returns the textual operator name

# File lib/onapp_market/api/query/operators.rb, line 83
def to_s
  @operator
end