Class: FrOData::Properties::Collection

Inherits:
FrOData::Property show all
Defined in:
lib/frodata/properties/collection.rb

Overview

Defines the Collection FrOData type.

Instance Attribute Summary

Attributes inherited from FrOData::Property

#name, #options

Instance Method Summary collapse

Methods inherited from FrOData::Property

#==, #allows_nil?, #concurrency_mode, from_xml, #json_value, #strict?, #to_xml, #xml_value

Constructor Details

#initialize(name, value, options = {}) ⇒ Collection

Overriding default constructor to avoid converting value to string. TODO: Make this the default for all property types?



8
9
10
11
# File 'lib/frodata/properties/collection.rb', line 8

def initialize(name, value, options = {})
  super(name, value, options)
  self.value = value
end

Instance Method Details

#typeObject



37
38
39
# File 'lib/frodata/properties/collection.rb', line 37

def type
  "Collection(#{value_type})"
end

#type_classObject



45
46
47
# File 'lib/frodata/properties/collection.rb', line 45

def type_class
  FrOData::PropertyRegistry[value_type]
end

#url_valueObject



33
34
35
# File 'lib/frodata/properties/collection.rb', line 33

def url_value
  '[' + @value.map(&:url_value).join(',') + ']'
end

#valueObject



13
14
15
16
17
18
19
# File 'lib/frodata/properties/collection.rb', line 13

def value
  if @value.nil?
    nil
  else
    @value.map(&:value)
  end
end

#value=(value) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/frodata/properties/collection.rb', line 21

def value=(value)
  if value.nil? && allows_nil?
    @value = nil
  elsif value.respond_to?(:map)
    @value = value.map.with_index do |element, index|
      type_class.new("#{name}[#{index}]", element)
    end
  else
    validation_error 'Value must be an array'
  end
end

#value_typeObject



41
42
43
# File 'lib/frodata/properties/collection.rb', line 41

def value_type
  options[:value_type] || 'Edm.String'
end