Class: AutotaskApi::Condition
- Inherits:
-
Object
- Object
- AutotaskApi::Condition
- Defined in:
- lib/autotask_api/query.rb
Instance Attribute Summary collapse
-
#expressions ⇒ Object
readonly
Returns the value of attribute expressions.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(expressions, operator = 'AND') ⇒ Condition
constructor
A new instance of Condition.
- #remove_expression_by_field(field) ⇒ Object
- #to_xml(xml) ⇒ Object
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
#expressions ⇒ Object (readonly)
Returns the value of attribute expressions.
44 45 46 |
# File 'lib/autotask_api/query.rb', line 44 def expressions @expressions end |
#operator ⇒ Object (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 |