Class: Occi::Core::Attributes
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- Occi::Core::Attributes
- Defined in:
- lib/occi/core/attributes.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#combine ⇒ Array
Key value pair of full attribute names with their corresponding values.
-
#convert_value(val, duping = false) ⇒ Object
:nodoc:.
-
#inspect ⇒ String
Json representation.
Class Method Details
.split(attributes) ⇒ Occi::Core::Attributes
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
#combine ⇒ Array
Returns 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 |
#inspect ⇒ String
Returns json representation.
38 39 40 |
# File 'lib/occi/core/attributes.rb', line 38 def inspect JSON.pretty_generate(JSON.parse(to_json)) end |