Class: WBEM::CIMProperty

Inherits:
XMLObject show all
Includes:
Comparable
Defined in:
lib/wbem/cim_obj.rb

Overview

Object value elements

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from XMLObject

#cmpname, #eql?, #hash, #nilcmp, #toxml

Constructor Details

#initialize(name, value, type = nil, class_origin = nil, propagated = nil, is_array = false, qualifiers = {}, reference_class = nil, array_size = nil) ⇒ CIMProperty

Returns a new instance of CIMProperty.



368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/wbem/cim_obj.rb', line 368

def initialize(name, value, type=nil, class_origin=nil, propagated=nil,
               is_array = false, qualifiers = {},
               reference_class = nil, array_size = nil)
    #"""Construct a new CIMProperty
    #Either the type or the value must be given.  If the value is not
    #given, it is left as nil.  If the type is not given, it is implied
    #from the value."""
    unless name.kind_of?(String)
        raise TypeError, "name argument must be a string"
    end
    unless (class_origin.nil? or class_origin.kind_of?(String))
        raise TypeError, "class_origin argument must be a string"
    end

    @name = name
    @value = value
    @prop_type = type
    @class_origin = class_origin
    @propagated = propagated
    @qualifiers = NocaseHash.new(qualifiers)
    @is_array = is_array
    @array_size = array_size
    @reference_class = reference_class

    if type.nil?
        if (value.nil?)
            raise TypeError, "value argument must not be nil if type is missing"
        end
        if (value.is_a?(Array))
            if (value.empty?)
                raise TypeError, "Empty property array #{name} must have a type"
            end
            @is_array = true
            @prop_type = WBEM.cimtype(value[0])
        else
            @prop_type = WBEM.cimtype(value)
        end
    else
        @is_array = true if (value.is_a?(Array))
        @prop_type = type
    end
    @value = value
end

Instance Attribute Details

#array_sizeObject

Returns the value of attribute array_size.



366
367
368
# File 'lib/wbem/cim_obj.rb', line 366

def array_size
  @array_size
end

#class_originObject

Returns the value of attribute class_origin.



366
367
368
# File 'lib/wbem/cim_obj.rb', line 366

def class_origin
  @class_origin
end

#is_arrayObject

Returns the value of attribute is_array.



366
367
368
# File 'lib/wbem/cim_obj.rb', line 366

def is_array
  @is_array
end

#nameObject

Returns the value of attribute name.



366
367
368
# File 'lib/wbem/cim_obj.rb', line 366

def name
  @name
end

#prop_typeObject

Returns the value of attribute prop_type.



366
367
368
# File 'lib/wbem/cim_obj.rb', line 366

def prop_type
  @prop_type
end

#propagatedObject

Returns the value of attribute propagated.



366
367
368
# File 'lib/wbem/cim_obj.rb', line 366

def propagated
  @propagated
end

#qualifiersObject

Returns the value of attribute qualifiers.



366
367
368
# File 'lib/wbem/cim_obj.rb', line 366

def qualifiers
  @qualifiers
end

#reference_classObject

Returns the value of attribute reference_class.



366
367
368
# File 'lib/wbem/cim_obj.rb', line 366

def reference_class
  @reference_class
end

#valueObject

Returns the value of attribute value.



366
367
368
# File 'lib/wbem/cim_obj.rb', line 366

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
# File 'lib/wbem/cim_obj.rb', line 438

def <=>(other)
    if equal?(other)
        ret_val = 0
    elsif (!other.kind_of?(CIMProperty ))
        ret_val = 1
    else
        ret_val = cmpname(self.name, other.name)
        ret_val = nilcmp(self.value, other.value) if (ret_val == 0)
        ret_val = nilcmp(self.prop_type, other.prop_type) if (ret_val == 0)
        ret_val = nilcmp(self.class_origin, other.class_origin) if (ret_val == 0)
        ret_val = nilcmp(self.propagated, other.propagated) if (ret_val == 0)
        ret_val = nilcmp(self.qualifiers, other.qualifiers) if (ret_val == 0)
        ret_val = nilcmp(self.is_array, other.is_array) if (ret_val == 0)
        ret_val = cmpname(self.reference_class, other.reference_class) if (ret_val == 0)
    end
    ret_val
end

#cloneObject



416
417
418
419
420
421
422
423
424
425
426
# File 'lib/wbem/cim_obj.rb', line 416

def clone
    return CIMProperty.new(self.name,
                           self.value,
                           self.prop_type,
                           self.class_origin,
                           self.propagated,
                           self.is_array,
                           self.qualifiers,
                           self.reference_class,
                           self.array_size)
end

#to_sObject



428
429
430
431
432
433
434
435
436
# File 'lib/wbem/cim_obj.rb', line 428

def to_s
    r = "#{self.class}(name=#{self.name}, type=#{self.prop_type}"
    r += ", class_origin=#{self.class_origin}" if self.class_origin
    r += ", propagated=#{self.propagated}" if self.propagated
    r += ", value=#{self.value}" if self.value
    r += ", qualifiers=#{self.qualifiers}" if self.qualifiers
    r += ", is_array=#{self.is_array}"
    r += ")"
end

#tocimxmlObject



456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
# File 'lib/wbem/cim_obj.rb', line 456

def tocimxml
    if self.is_array
        return PROPERTY_ARRAY.new(self.name,
                                  self.prop_type,
                                  WBEM.tocimxml(self.value),
                                  self.array_size,
                                  self.class_origin,
                                  self.propagated,
                                  self.qualifiers.values.collect { |q| q.tocimxml})
    elsif self.prop_type == 'reference'
        return PROPERTY_REFERENCE.new(self.name,
                                      WBEM.tocimxml(self.value, true),
                                      self.reference_class,
                                      self.class_origin,
                                      self.propagated,
                                      self.qualifiers.values.collect { |q| q.tocimxml})
    else
        return PROPERTY.new(self.name,
                            self.prop_type,
                            WBEM.tocimxml(self.value),
                            self.class_origin,
                            self.propagated,
                            self.qualifiers.values.collect { |q| q.tocimxml})
    end
end