Class: OData::ComplexType

Inherits:
Object
  • Object
show all
Defined in:
lib/odata/complex_type.rb

Overview

ComplexTypes are used in OData to either encapsulate richer data types for use as Entity properties. ComplexTypes are composed of properties the same way that Entities are and, so, the interface for working with the various properties of a ComplexType mimics that of Entities.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ self

Creates a new ComplexType based on the supplied options.

Parameters:

  • options (Hash) (defaults to: {})


13
14
15
16
17
18
19
20
# File 'lib/odata/complex_type.rb', line 13

def initialize(options = {})
  validate_options(options)

  @name = options[:name].to_s
  @service = options[:service]

  collect_properties
end

Instance Attribute Details

#nameObject (readonly)

The name of the ComplexType



8
9
10
# File 'lib/odata/complex_type.rb', line 8

def name
  @name
end

Instance Method Details

#[](property_name) ⇒ *

Returns the value of the requested property.

Parameters:

  • property_name (to_s)

Returns:

  • (*)


43
44
45
# File 'lib/odata/complex_type.rb', line 43

def [](property_name)
  properties[property_name.to_s].value
end

#[]=(property_name, value) ⇒ *

Sets the value of the named property.

Parameters:

  • property_name (to_s)
  • value (*)

Returns:

  • (*)


51
52
53
# File 'lib/odata/complex_type.rb', line 51

def []=(property_name, value)
  properties[property_name.to_s].value = value
end

#namespaceString

Returns the namespace this ComplexType belongs to.

Returns:

  • (String)


30
31
32
# File 'lib/odata/complex_type.rb', line 30

def namespace
  @namespace ||= service.namespace
end

#property_namesArray<String>

Returns a list of this ComplexType’s property names.

Returns:

  • (Array<String>)


36
37
38
# File 'lib/odata/complex_type.rb', line 36

def property_names
  @property_names ||= properties.collect {|name, property| name}
end

#to_xml(xml_builder) ⇒ Object

Returns the XML representation of the property to the supplied XML builder.

Parameters:

  • xml_builder (Nokogiri::XML::Builder)


58
59
60
61
62
63
64
65
66
67
68
# File 'lib/odata/complex_type.rb', line 58

def to_xml(xml_builder)
  attributes = {
      'metadata:type' => type,
  }

  xml_builder['data'].send(name.to_sym, attributes) do
    properties.each do |name, property|
      property.to_xml(xml_builder)
    end
  end
end

#typeString

Returns the namespaced type for the ComplexType.

Returns:

  • (String)


24
25
26
# File 'lib/odata/complex_type.rb', line 24

def type
  "#{namespace}.#{name}"
end