Class: DynamicsCRM::Metadata::FilterExpression
- Inherits:
-
Object
- Object
- DynamicsCRM::Metadata::FilterExpression
- Defined in:
- lib/dynamics_crm/metadata/filter_expression.rb
Instance Attribute Summary collapse
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#operator ⇒ Object
Returns the value of attribute operator.
Instance Method Summary collapse
- #add_condition(condition) ⇒ Object
- #get_type(value) ⇒ Object
-
#initialize(operator, conditions = []) ⇒ FilterExpression
constructor
A new instance of FilterExpression.
- #to_xml(options = {}) ⇒ Object
Constructor Details
#initialize(operator, conditions = []) ⇒ FilterExpression
Returns a new instance of FilterExpression.
7 8 9 10 |
# File 'lib/dynamics_crm/metadata/filter_expression.rb', line 7 def initialize(operator, conditions=[]) @operator = operator || 'And' @conditions = conditions end |
Instance Attribute Details
#conditions ⇒ Object
Returns the value of attribute conditions.
5 6 7 |
# File 'lib/dynamics_crm/metadata/filter_expression.rb', line 5 def conditions @conditions end |
#operator ⇒ Object
Returns the value of attribute operator.
5 6 7 |
# File 'lib/dynamics_crm/metadata/filter_expression.rb', line 5 def operator @operator end |
Instance Method Details
#add_condition(condition) ⇒ Object
12 13 14 |
# File 'lib/dynamics_crm/metadata/filter_expression.rb', line 12 def add_condition(condition) @conditions << condition end |
#get_type(value) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/dynamics_crm/metadata/filter_expression.rb', line 16 def get_type(value) type = value.class.to_s.downcase type = "int" if type == "fixnum" type = "boolean" if ["trueclass", "falseclass"].include?(type) type end |
#to_xml(options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/dynamics_crm/metadata/filter_expression.rb', line 23 def to_xml(={}) ns = [:namespace] ? [:namespace] : "a" expressions = "" @conditions.each do |condition| attr_name, op, value = condition expressions << %Q{ <#{ns}:MetadataConditionExpression> <#{ns}:PropertyName>#{attr_name}</#{ns}:PropertyName> <#{ns}:ConditionOperator>#{op}</#{ns}:ConditionOperator> <#{ns}:Value i:type='e:#{get_type(value)}' xmlns:e='http://www.w3.org/2001/XMLSchema'>#{value}</#{ns}:Value> </#{ns}:MetadataConditionExpression>} end %Q{<#{ns}:Criteria> <#{ns}:Conditions> #{expressions} </#{ns}:Conditions> <#{ns}:FilterOperator>#{@operator}</#{ns}:FilterOperator> </#{ns}:Criteria>} end |