Class: DynamicsCRM::XML::EntityReference

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamics_crm/xml/entity_reference.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logical_name, id) ⇒ EntityReference

Returns a new instance of EntityReference.



8
9
10
11
# File 'lib/dynamics_crm/xml/entity_reference.rb', line 8

def initialize(logical_name, id)
  @logical_name = logical_name
  @id = id || "00000000-0000-0000-0000-000000000000"
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/dynamics_crm/xml/entity_reference.rb', line 6

def id
  @id
end

#logical_nameObject

Returns the value of attribute logical_name.



6
7
8
# File 'lib/dynamics_crm/xml/entity_reference.rb', line 6

def logical_name
  @logical_name
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/dynamics_crm/xml/entity_reference.rb', line 6

def name
  @name
end

#namespaceObject

Returns the value of attribute namespace.



6
7
8
# File 'lib/dynamics_crm/xml/entity_reference.rb', line 6

def namespace
  @namespace
end

Class Method Details

.from_xml(xml_document) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dynamics_crm/xml/entity_reference.rb', line 39

def self.from_xml(xml_document)
  entity_ref = EntityReference.new('unknown', nil)

  if xml_document
    xml_document.each_element do |node|
      attr_name = ::DynamicsCRM::StringUtil.underscore(node.name).to_sym
      if entity_ref.respond_to?(attr_name)
        entity_ref.send("#{attr_name}=", node.text ? node.text.strip : nil)
      end
    end
  end

  return entity_ref
end

Instance Method Details

#to_hashObject



31
32
33
34
35
36
37
# File 'lib/dynamics_crm/xml/entity_reference.rb', line 31

def to_hash
  {
    :logical_name => @logical_name,
    :id => @id,
    :name => @name,
  }
end

#to_xml(options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dynamics_crm/xml/entity_reference.rb', line 13

def to_xml(options={})
  namespace = options[:namespace] ? "#{options[:namespace]}:" : ''

  xml = %Q{
    <#{namespace}Id>#{@id}</#{namespace}Id>
    <#{namespace}LogicalName>#{@logical_name}</#{namespace}LogicalName>
    <#{namespace}Name #{@name ? '' : 'nil="true"'}>#{@name}</#{namespace}Name>
  }
  # Associate/Disassociate request requires CamelCase while others require lowerCase
  tag_name = options[:camel_case] ? "EntityReference" : "entityReference"
  if options[:exclude_root].nil?
  xml = %Q{
  <#{namespace}#{tag_name}>#{xml}</#{namespace}#{tag_name}>
  }
  end
  return xml
end