Class: Dynamicloud::API::Criteria::INCondition

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

Overview

This class represents an IN and NOT IN condition.

Author:

  • Eleazar Gomez

Since:

  • 8/24/15

Version:

  • 1.0.0

Constant Summary

Constants inherited from Condition

Condition::ROOT, Condition::WITHOUT

Instance Method Summary collapse

Constructor Details

#initialize(left, values, not_in = false) ⇒ INCondition

Constructor to build either IN or NOT IN condition

Parameters:

  • left

    attribute to compare

  • values

    values to use to build IN or NOT IN condition

  • not_in (defaults to: false)

    indicates if this condition is a not in.

Since:

  • 8/24/15



258
259
260
261
262
# File 'lib/dynamic_criteria.rb', line 258

def initialize(left, values, not_in = false)
  @left = left
  @values = values
  @not_in = not_in
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/24/15



267
268
269
270
271
272
273
274
275
276
# File 'lib/dynamic_criteria.rb', line 267

def to_record_string(parent)
  condition = '"' + @left + '": {' + (@not_in ? '"$nin"' : '"$in"') + ': ['

  items = ''
  @values.each do |value|
    items = items + ((items.length == 0 ? '' : ',') + (value.is_a?(String) ? '"' : '') + value.to_s + (value.is_a?(String) ? '"' : ''))
  end

  condition + items + ']}'
end