Class: OData::ComplexType
- Inherits:
-
Object
- Object
- OData::ComplexType
- 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
-
#name ⇒ Object
readonly
The name of the ComplexType.
Instance Method Summary collapse
-
#[](property_name) ⇒ *
Returns the value of the requested property.
-
#[]=(property_name, value) ⇒ *
Sets the value of the named property.
-
#initialize(options = {}) ⇒ self
constructor
Creates a new ComplexType based on the supplied options.
-
#namespace ⇒ String
Returns the namespace this ComplexType belongs to.
-
#property_names ⇒ Array<String>
Returns a list of this ComplexType’s property names.
-
#to_xml(xml_builder) ⇒ Object
Returns the XML representation of the property to the supplied XML builder.
-
#type ⇒ String
Returns the namespaced type for the ComplexType.
Constructor Details
#initialize(options = {}) ⇒ self
Creates a new ComplexType based on the supplied options.
13 14 15 16 17 18 19 20 |
# File 'lib/odata/complex_type.rb', line 13 def initialize( = {}) () @name = [:name].to_s @service = [:service] collect_properties end |
Instance Attribute Details
#name ⇒ Object (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.
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.
51 52 53 |
# File 'lib/odata/complex_type.rb', line 51 def []=(property_name, value) properties[property_name.to_s].value = value end |
#namespace ⇒ String
Returns the namespace this ComplexType belongs to.
30 31 32 |
# File 'lib/odata/complex_type.rb', line 30 def namespace @namespace ||= service.namespace end |
#property_names ⇒ Array<String>
Returns a list of this ComplexType’s property names.
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.
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 |
#type ⇒ String
Returns the namespaced type for the ComplexType.
24 25 26 |
# File 'lib/odata/complex_type.rb', line 24 def type "#{namespace}.#{name}" end |