Class: FrOData::Properties::Complex
- Inherits:
-
FrOData::Property
- Object
- FrOData::Property
- FrOData::Properties::Complex
- Defined in:
- lib/frodata/properties/complex.rb
Overview
Abstract base class for FrOData ComplexTypes
Instance Attribute Summary
Attributes inherited from FrOData::Property
Class Method Summary collapse
-
.from_xml(property_xml, options = {}) ⇒ FrOData::Property
Creates a new property instance from an XML element.
Instance Method Summary collapse
-
#[](property_name) ⇒ *
Returns the value of the requested property.
-
#[]=(property_name, value) ⇒ *
Sets the value of the named property.
-
#initialize(name, value, options = {}) ⇒ Complex
constructor
A new instance of Complex.
-
#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.
-
#value ⇒ Hash?
Returns the property value, properly typecast.
-
#value=(new_value) ⇒ Object
Sets the property value.
Methods inherited from FrOData::Property
#==, #allows_nil?, #concurrency_mode, #json_value, #strict?, #type, #url_value, #xml_value
Constructor Details
#initialize(name, value, options = {}) ⇒ Complex
Returns a new instance of Complex.
6 7 8 9 |
# File 'lib/frodata/properties/complex.rb', line 6 def initialize(name, value, = {}) super(name, value, ) init_properties end |
Class Method Details
.from_xml(property_xml, options = {}) ⇒ FrOData::Property
Creates a new property instance from an XML element
72 73 74 75 76 |
# File 'lib/frodata/properties/complex.rb', line 72 def self.from_xml(property_xml, = {}) nodes = property_xml.element_children props = Hash[nodes.map { |el| [el.name, el.content] }] new(property_xml.name, props.to_json, ) end |
Instance Method Details
#[](property_name) ⇒ *
Returns the value of the requested property.
41 42 43 |
# File 'lib/frodata/properties/complex.rb', line 41 def [](property_name) properties[property_name.to_s].value end |
#[]=(property_name, value) ⇒ *
Sets the value of the named property.
49 50 51 |
# File 'lib/frodata/properties/complex.rb', line 49 def []=(property_name, value) properties[property_name.to_s].value = value end |
#property_names ⇒ Array<String>
Returns a list of this ComplexType’s property names.
34 35 36 |
# File 'lib/frodata/properties/complex.rb', line 34 def property_names @property_names ||= properties.keys end |
#to_xml(xml_builder) ⇒ Object
Returns the XML representation of the property to the supplied XML builder.
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/frodata/properties/complex.rb', line 56 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 |
#value ⇒ Hash?
Returns the property value, properly typecast
13 14 15 16 17 18 19 |
# File 'lib/frodata/properties/complex.rb', line 13 def value if allows_nil? && properties.values.all?(&:nil?) nil else Hash[properties.map { |key, value| [key, value.value] }] end end |
#value=(new_value) ⇒ Object
Sets the property value
23 24 25 26 27 28 29 30 |
# File 'lib/frodata/properties/complex.rb', line 23 def value=(new_value) validate(new_value) if new_value.nil? property_names.each { |name| self[name] = nil } else property_names.each { |name| self[name] = new_value[name] } end end |