Class: AutotaskApi::Condition

Inherits:
Object
  • Object
show all
Defined in:
lib/autotask_api/query.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expressions, operator = 'AND') ⇒ Condition

Returns a new instance of Condition.



46
47
48
49
# File 'lib/autotask_api/query.rb', line 46

def initialize(expressions, operator = 'AND')
  @expressions = expressions.is_a?(Array) ? expressions : [expressions]
  @operator = operator
end

Instance Attribute Details

#expressionsObject (readonly)

Returns the value of attribute expressions.



44
45
46
# File 'lib/autotask_api/query.rb', line 44

def expressions
  @expressions
end

#operatorObject (readonly)

Returns the value of attribute operator.



44
45
46
# File 'lib/autotask_api/query.rb', line 44

def operator
  @operator
end

Class Method Details

.from_hash(condition = {}) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/autotask_api/query.rb', line 57

def self.from_hash(condition = {})
  expressions = condition[:expressions].map do |expression|
    expression.has_key?(:expressions) ? Condition.from_hash(expression) : Expression.from_hash(expression)
  end

  new expressions, condition[:operator] || 'AND'
end

Instance Method Details

#remove_expression_by_field(field) ⇒ Object



65
66
67
68
69
# File 'lib/autotask_api/query.rb', line 65

def remove_expression_by_field(field)
  expressions.reject! do |expression|
    expression.is_a?(Condition) ? expression.remove_expression_by_field(field) : expression.field == field
  end
end

#to_xml(xml) ⇒ Object



51
52
53
54
55
# File 'lib/autotask_api/query.rb', line 51

def to_xml(xml)
  xml.condition do
    expressions.each { |expression| expression.to_xml(xml) }
  end
end