class OnappMarket::API::Query::MultiOperator

Class representing a multi parameter operator, such as AND.

Public Class Methods

new(operator, nodes) click to toggle source

Create a new instance

Attributes

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

  • +*nodes+ - nodes - which may be any Operator or Comparator

# File lib/onapp_market/api/query/operators.rb, line 100
def initialize(operator, nodes)
  @operator = operator
  super(nodes)
end

Public Instance Methods

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

Flatten this operator and children as per a regular expression.

Yields each element of the flattened experssion

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

# File lib/onapp_market/api/query/operators.rb, line 118
def flatten(&block)
  # Helper for precedence
  yield OpenParenthese.new
  self.leaves.each do |n|
    # Only yield operator between leaves
    yield self if n != self.leaves.first
    # If a comparator - simply yield
    yield n if n.is_a? Comparator
    # If an Operator - flatten also
    yield n.flatten(&block) if n.is_a? Operator
  end
  # Helper for precedence
  yield CloseParenthese.new
end
to_hash() click to toggle source
# File lib/onapp_market/api/query/operators.rb, line 133
def to_hash
  {"type" => "MultiOperator", "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 107
def to_s
  @operator
end