class Praxis::Extensions::AttributeFiltering::FilteringParams::ConditionGroup
An Object that represents an AST tree for either an OR or an AND conditions to be applied to its items children
Attributes
Public Class Methods
Source
# File lib/praxis/extensions/attribute_filtering/filters_parser.rb, line 152 def self.compress_tree(node:, operator:) return [node] if node[:triad] # It is an op node if node[:o] == operator # compatible op as parent, collect my compacted children and return them up skipping my op resultl = compress_tree(node: node[:l], operator: operator) resultr = compress_tree(node: node[:r], operator: operator) resultl + resultr else collected = compress_tree(node: node, operator: node[:o]) [{ op: node[:o], items: collected }] end end
Given a binary tree of operand conditions, transform it to a multi-leaf tree where a single condition node has potentially multiple subtrees for the same operation (instead of 2) For example (&, (&, a, b), (|, c, d)) => (&, a, b, (|, c, d))
Source
# File lib/praxis/extensions/attribute_filtering/filters_parser.rb, line 111 def self.load(node) if node[:o] compactedl = compress_tree(node: node[:l], operator: node[:o]) compactedr = compress_tree(node: node[:r], operator: node[:o]) compacted = { op: node[:o], items: compactedl + compactedr } loaded = ConditionGroup.new(**compacted, parent_group: nil) else loaded = Condition.new(triad: node[:triad], parent_group: nil) end loaded end
Source
# File lib/praxis/extensions/attribute_filtering/filters_parser.rb, line 125 def initialize(op:, items:, parent_group:) @type = op.to_s == '&' ? :and : :or @items = items.map do |item| if item[:op] ConditionGroup.new(**item, parent_group: self) else Condition.new(triad: item[:triad], parent_group: self) end end @parent_group = parent_group end
rubocop:disable Naming/MethodParameterName
Public Instance Methods
Source
# File lib/praxis/extensions/attribute_filtering/filters_parser.rb, line 138 def dump "( #{@items.map(&:dump).join(" #{type.upcase} ")} )" end
rubocop:enable Naming/MethodParameterName
Source
# File lib/praxis/extensions/attribute_filtering/filters_parser.rb, line 143 def flattened_conditions @items.inject([]) do |accum, item| accum + item.flattened_conditions end end
Returns an array with flat conditions from all child triad conditions