Class: Occi::Core::Attributes

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/occi/core/attributes.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.split(attributes) ⇒ Occi::Core::Attributes

Parameters:

  • attributes (Hash)

    key value pair of full attribute names with their corresponding values

Returns:



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/occi/core/attributes.rb', line 44

def self.split(attributes)
  attribute = Attributes.new
  attributes.each do |name, value|
    Occi::Log.debug "Attribute named #{name}"
    key, _, rest = name.partition('.')
    if rest.empty?
      attribute[key] = value
    else
      attribute.merge! Attributes.new(key => self.split(rest => value))
    end
  end
  return attribute
end

Instance Method Details

#combineArray

Returns key value pair of full attribute names with their corresponding values.

Returns:

  • (Array)

    key value pair of full attribute names with their corresponding values



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/occi/core/attributes.rb', line 8

def combine
  hash = { }
  self.each_key do |key|
    if self[key].kind_of? Occi::Core::Attributes
      self[key].combine.each_pair { |k, v| hash[key + '.' + k] = v }
    else
      hash[key] = self[key]
    end
  end
  hash
end

#convert_value(val, duping = false) ⇒ Object

:nodoc:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/occi/core/attributes.rb', line 20

def convert_value(val, duping=false) #:nodoc:
  case val
    when self.class
      val.dup
    when Hashie::Mash
      val = val.dup if duping
      val
    when ::Hash
      val = val.dup if duping
      self.class.subkey_class.new.merge(val)
    when Array
      val.collect { |e| convert_value(e) }
    else
      val
  end
end

#inspectString

Returns json representation.

Returns:

  • (String)

    json representation



38
39
40
# File 'lib/occi/core/attributes.rb', line 38

def inspect
  JSON.pretty_generate(JSON.parse(to_json))
end