Class: WBEM::NocaseHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/wbem/cim_obj.rb

Instance Method Summary collapse

Constructor Details

#initialize(initial_values = {}) ⇒ NocaseHash

Returns a new instance of NocaseHash.



41
42
43
44
45
46
47
48
49
# File 'lib/wbem/cim_obj.rb', line 41

def initialize(initial_values = {})
    super()
    initial_values = initial_values.to_a if initial_values.is_a?(Hash)
    if initial_values.is_a?(Array)
        initial_values.each do |item|
            self[item[0]] = item[1] if item.is_a?(Array)
        end
    end
end

Instance Method Details

#==(other) ⇒ Object



82
83
84
85
86
87
# File 'lib/wbem/cim_obj.rb', line 82

def ==(other)
    self.each do |key, value|
        return false unless (other.include?(key) and other[key] == value)
    end
    return self.length == other.length
end

#[](key) ⇒ Object



54
55
56
57
# File 'lib/wbem/cim_obj.rb', line 54

def [](key)
    v = super(get_key(key))
    v[1] unless v.nil?
end

#[]=(key, value) ⇒ Object



58
59
60
61
62
63
# File 'lib/wbem/cim_obj.rb', line 58

def []=(key, value)
    unless key.is_a?(String)
        raise IndexError, "Key must be a String"
    end
    super(get_key(key),[key, value])
end

#cloneObject Also known as: copy



104
105
106
# File 'lib/wbem/cim_obj.rb', line 104

def clone
    return NocaseHash.new(self)
end

#delete(key) ⇒ Object



89
90
91
# File 'lib/wbem/cim_obj.rb', line 89

def delete(key)
    super(get_key(key))
end

#each(&block) ⇒ Object



76
77
78
# File 'lib/wbem/cim_obj.rb', line 76

def each(&block)
    to_a.each(&block)
end

#fetch(key) ⇒ Object



92
93
94
# File 'lib/wbem/cim_obj.rb', line 92

def fetch(key)
    super(get_key(key))[1]
end

#get_key(key) ⇒ Object



51
52
53
# File 'lib/wbem/cim_obj.rb', line 51

def get_key(key)
    key.is_a?(String) ? key.downcase : key
end

#has_key?(key) ⇒ Boolean

Returns:



95
96
97
# File 'lib/wbem/cim_obj.rb', line 95

def has_key?(key)
    super(get_key(key))
end

#include?(key) ⇒ Boolean

Returns:



98
99
100
# File 'lib/wbem/cim_obj.rb', line 98

def include?(key)
    super(get_key(key))
end

#keysObject



67
68
69
# File 'lib/wbem/cim_obj.rb', line 67

def keys
    rawvalues.collect { |v| v[0] }
end

#rawarrayObject



66
# File 'lib/wbem/cim_obj.rb', line 66

alias rawarray to_a

#rawkeysObject



64
# File 'lib/wbem/cim_obj.rb', line 64

alias rawkeys keys

#rawvaluesObject



65
# File 'lib/wbem/cim_obj.rb', line 65

alias rawvalues values

#sortObject



79
80
81
# File 'lib/wbem/cim_obj.rb', line 79

def sort 
    rawarray.sort.collect { |k,v| [v[0], v[1]] }
end

#to_aObject



73
74
75
# File 'lib/wbem/cim_obj.rb', line 73

def to_a
    super.collect { |k,v| [v[0], v[1]] }
end

#update(otherHash) ⇒ Object



101
102
103
# File 'lib/wbem/cim_obj.rb', line 101

def update(otherHash)
    otherHash.to_a.each { |key, value| self[key] = value }
end

#valuesObject



70
71
72
# File 'lib/wbem/cim_obj.rb', line 70

def values
    super.collect { |v| v[1] }
end