Class: WBEM::CIMInstance

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from XMLObject

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

Constructor Details

#initialize(classname, properties = {}, qualifiers = {}, path = nil) ⇒ CIMInstance

Returns a new instance of CIMInstance.



664
665
666
667
668
669
670
671
672
673
674
675
# File 'lib/wbem/cim_obj.rb', line 664

def initialize(classname, properties = {}, qualifiers = {},
               path = nil)
    #"""Create CIMInstance.
    
    @classname = classname
    @qualifiers = NocaseHash.new(qualifiers)
    @path = path
    @properties = NocaseHash.new
    properties.each do |k, v|
        self[k]=v
    end
end

Instance Attribute Details

#classnameObject

The properties is indexed by name and points to CIMProperty instances.“”“



662
663
664
# File 'lib/wbem/cim_obj.rb', line 662

def classname
  @classname
end

#pathObject

The properties is indexed by name and points to CIMProperty instances.“”“



662
663
664
# File 'lib/wbem/cim_obj.rb', line 662

def path
  @path
end

#propertiesObject

The properties is indexed by name and points to CIMProperty instances.“”“



662
663
664
# File 'lib/wbem/cim_obj.rb', line 662

def properties
  @properties
end

#qualifiersObject

The properties is indexed by name and points to CIMProperty instances.“”“



662
663
664
# File 'lib/wbem/cim_obj.rb', line 662

def qualifiers
  @qualifiers
end

Instance Method Details

#<=>(other) ⇒ Object



692
693
694
695
696
697
698
699
700
701
702
703
704
705
# File 'lib/wbem/cim_obj.rb', line 692

def <=>(other)
    if equal?(other)
        return 0
    elsif (!other.kind_of?(CIMInstance))
        return 1
    end
    ## TODO: Allow for the type to be null as long as the values
    ## are the same and non-null?
    ret_val = cmpname(self.classname, other.classname)
    ret_val = nilcmp(self.path, other.path) if (ret_val == 0)
    ret_val = nilcmp(self.properties, other.properties) if (ret_val == 0)
    ret_val = nilcmp(self.qualifiers, other.qualifiers) if (ret_val == 0)
    ret_val
end

#[](key) ⇒ Object



719
720
721
722
# File 'lib/wbem/cim_obj.rb', line 719

def [](key) 
    ret = self.properties[key]
    ret = ret.value unless ret.nil?
end

#[]=(key, value) ⇒ Object

def iterkeys(self): return self.properties.iterkeys() def itervalues(self): return self.properties.itervalues() def iteritems(self): return self.properties.iteritems()



745
746
747
748
749
750
751
752
753
754
755
756
757
# File 'lib/wbem/cim_obj.rb', line 745

def []=(key, value) 
    
    # Don't let anyone set integer or float values.  You must use
    # a subclass from the cim_type module.
    
    unless (value.is_a?(CIMProperty))
        unless WBEM.valid_cimtype?(value)
            raise TypeError, "Must use a CIM type assigning numeric values."
        end
        value = CIMProperty.new(key, value)
    end
    self.properties[key] = value
end

#cloneObject



677
678
679
# File 'lib/wbem/cim_obj.rb', line 677

def clone
    CIMInstance.new(@classname, @properties, @qualifiers, @path)
end

#delete(key) ⇒ Object



723
724
725
# File 'lib/wbem/cim_obj.rb', line 723

def delete(key) 
    self.properties.delete(key)
end

#fetch(key) ⇒ Object

A whole bunch of dictionary methods that map to the equivalent operation on self.properties.



716
717
718
# File 'lib/wbem/cim_obj.rb', line 716

def fetch(key) 
    return self.properties.fetch(key)
end

#has_key?(key) ⇒ Boolean

Returns:



729
730
731
# File 'lib/wbem/cim_obj.rb', line 729

def has_key?(key)
    self.properties.has_key?(key)
end

#keysObject



732
733
734
# File 'lib/wbem/cim_obj.rb', line 732

def keys
    self.properties.keys()
end

#lengthObject



726
727
728
# File 'lib/wbem/cim_obj.rb', line 726

def length
    self.properties.length 
end

#to_aObject



738
739
740
# File 'lib/wbem/cim_obj.rb', line 738

def to_a
    self.properties.to_a.collect { |k, v| [k, v.value] }
end

#to_sObject



707
708
709
710
711
# File 'lib/wbem/cim_obj.rb', line 707

def to_s
    # Don't show all the properties and qualifiers because they're
    # just too big
    "#{self.class}(classname=#{self.classname} ...)"
end

#tocimxmlObject



759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
# File 'lib/wbem/cim_obj.rb', line 759

def tocimxml
    props = []
    self.properties.each do |key, prop|
        if (prop.is_a?(CIMProperty))
            props << prop
        else
            props << CIMProperty.new(key, prop)
        end
    end
    instance_xml = INSTANCE.new(self.classname, 
                                props.collect { |p| p.tocimxml}, 
                                self.qualifiers.values.collect { |q| q.tocimxml})
    if self.path.nil?
        return instance_xml
    end
    return VALUE_NAMEDINSTANCE.new(self.path.tocimxml,
                                   instance_xml)
end

#valuesObject



735
736
737
# File 'lib/wbem/cim_obj.rb', line 735

def values
    self.properties.values.collect { |v| v.value }
end