Class: Kaltura::KalturaClassFactory

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

Class Method Summary collapse

Class Method Details

.object_from_xml(xml_element) ⇒ Object



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/kaltura_client_base.rb', line 252

def self.object_from_xml(xml_element)
	instance = nil
       if xml_element.elements.size > 0
		if xml_element.elements[1].name == 'item' # array	
			instance = []
			xml_element.elements.each('item') do | element |
				instance.push(KalturaClassFactory.object_from_xml(element))
			end
		else # object
			object_type_element = xml_element.get_text('objectType')
			if (object_type_element != nil)
				object_class = xml_element.get_text('objectType').value
				instance = Object.const_get(object_class).new
				xml_element.elements.each do | element |
					value = KalturaClassFactory.object_from_xml(element)
					instance.send(self.underscore(element.name) + "=", value);
				end
			end
		end
	else # simple type
       	return xml_element.text
      	end
	
      	return instance;
end

.underscore(val) ⇒ Object



278
279
280
# File 'lib/kaltura_client_base.rb', line 278

def self.underscore(val)
	val.gsub(/(.)([A-Z])/,'\1_\2').downcase
end