Class: DynamicsCRM::XML::Entity
- Inherits:
-
Object
- Object
- DynamicsCRM::XML::Entity
- Defined in:
- lib/dynamics_crm/xml/entity.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#entity_state ⇒ Object
Returns the value of attribute entity_state.
-
#formatted_values ⇒ Object
Returns the value of attribute formatted_values.
-
#id ⇒ Object
Returns the value of attribute id.
-
#logical_name ⇒ Object
Returns the value of attribute logical_name.
-
#related_entities ⇒ Object
Returns the value of attribute related_entities.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(logical_name, id = nil) ⇒ Entity
constructor
A new instance of Entity.
- #to_hash ⇒ Object
-
#to_xml(options = {}) ⇒ Object
Using Entity vs entity causes the error: Value cannot be null.
Constructor Details
#initialize(logical_name, id = nil) ⇒ Entity
8 9 10 11 |
# File 'lib/dynamics_crm/xml/entity.rb', line 8 def initialize(logical_name, id=nil) @logical_name = logical_name @id = id || "00000000-0000-0000-0000-000000000000" end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/dynamics_crm/xml/entity.rb', line 6 def attributes @attributes end |
#entity_state ⇒ Object
Returns the value of attribute entity_state.
6 7 8 |
# File 'lib/dynamics_crm/xml/entity.rb', line 6 def entity_state @entity_state end |
#formatted_values ⇒ Object
Returns the value of attribute formatted_values.
6 7 8 |
# File 'lib/dynamics_crm/xml/entity.rb', line 6 def formatted_values @formatted_values end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/dynamics_crm/xml/entity.rb', line 6 def id @id end |
#logical_name ⇒ Object
Returns the value of attribute logical_name.
6 7 8 |
# File 'lib/dynamics_crm/xml/entity.rb', line 6 def logical_name @logical_name end |
#related_entities ⇒ Object
Returns the value of attribute related_entities.
6 7 8 |
# File 'lib/dynamics_crm/xml/entity.rb', line 6 def @related_entities end |
Class Method Details
.from_xml(xml_document) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dynamics_crm/xml/entity.rb', line 45 def self.from_xml(xml_document) entity = Entity.new('') if xml_document xml_document.elements.each do |node| attr_name = DynamicsCRM::StringUtil.underscore(node.name).to_sym if entity.respond_to?(attr_name) if node.name == "Attributes" entity.attributes = XML::Attributes.from_xml(node) elsif node.name == "FormattedValues" entity.formatted_values = XML::FormattedValues.from_xml(node) # Reset to nil if no values were found. entity.formatted_values = nil if entity.formatted_values.empty? else entity.send("#{attr_name}=", node.text ? node.text.strip : nil) end end end end return entity end |
Instance Method Details
#to_hash ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dynamics_crm/xml/entity.rb', line 34 def to_hash { :attributes => @attributes.to_hash, :entity_state => entity_state, :formatted_values => (@formatted_values ? @formatted_values.to_hash : nil), :id => @id, :logical_name => @logical_name, :related_entities => } end |
#to_xml(options = {}) ⇒ Object
Using Entity vs entity causes the error: Value cannot be null.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/dynamics_crm/xml/entity.rb', line 14 def to_xml(={}) inner_xml = %Q{ #{@attributes.is_a?(XML::Attributes) ? @attributes.to_xml : @attributes} <a:EntityState i:nil="true" /> <a:FormattedValues xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic" /> <a:Id>#{@id}</a:Id> <a:LogicalName>#{@logical_name}</a:LogicalName> <a:RelatedEntities xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic" /> } return inner_xml if [:exclude_root] %Q{ <entity xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts"> #{inner_xml} </entity> } end |