Class: NoBrainer::Criteria::Where::MultiOperator
- Inherits:
-
Struct
- Object
- Struct
- NoBrainer::Criteria::Where::MultiOperator
- Defined in:
- lib/no_brainer/criteria/where.rb
Instance Method Summary collapse
Instance Method Details
#simplify ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/no_brainer/criteria/where.rb', line 47 def simplify clauses = self.clauses.map(&:simplify) if clauses.size == 1 && clauses.first.is_a?(self.class) return clauses.first end same_op_clauses, other_clauses = clauses.partition do |v| v.is_a?(self.class) && (v.clauses.size == 1 || v.op == self.op) end simplified_clauses = other_clauses + same_op_clauses.flat_map(&:clauses) simplified_clauses = BinaryOperator.simplify_clauses(op, simplified_clauses.uniq) self.class.new(op, simplified_clauses) end |
#to_rql(doc) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/no_brainer/criteria/where.rb', line 61 def to_rql(doc) case op when :and then clauses.map { |c| c.to_rql(doc) }.reduce(:&) when :or then clauses.map { |c| c.to_rql(doc) }.reduce(:|) end end |