Class: Dynamicloud::API::Criteria::ORCondition

Inherits:
Condition
  • Object
show all
Defined in:
lib/dynamic_criteria.rb

Overview

This class represents an or condition. Implements condition to return a JSON according left and right parts.

Author:

  • Eleazar Gomez

Since:

  • 8/23/15

Version:

  • 1.0.0

Constant Summary

Constants inherited from Condition

Condition::ROOT, Condition::WITHOUT

Instance Method Summary collapse

Constructor Details

#initialize(left, right) ⇒ ORCondition

Constructor tha builds this condition

Parameters:

  • left

    attribute to compare

  • right

    right part of this or condition

Since:

  • 8/23/15



361
362
363
364
365
366
367
368
# File 'lib/dynamic_criteria.rb', line 361

def initialize(left, right)
  unless (left.is_a?(Condition)) || (right.is_a?(Condition))
    raise 'left and right should implement Condition'
  end

  @left = left
  @right = right
end

Instance Method Details

#to_record_string(parent) ⇒ Object

This method will return a String of this condition

Parameters:

  • parent

    this is the parent of this condition

Returns:

  • a json

Since:

  • 8/23/15



373
374
375
376
# File 'lib/dynamic_criteria.rb', line 373

def to_record_string(parent)
  (parent.is_a?(ORCondition) ? '' : '"$or": {') + @left.to_record_string(self) + ',' +
      @right.to_record_string(self) + (parent.is_a?(ORCondition) ? '' : '}')
end