class SoftLayer::ObjectMaskProperty
A class representing a SoftLayer Object's property as represented in an Object Mask.
The Object Mask Parser parses Object Mask Strings into ObjectMaskProperty structures.
Another useful property ObjectMaskProperty structures is that they can can merge with compatible structures to create a new structure which incorporates the properties of both, but in a streamlined construct
Attributes
children[R]
name[R]
type[R]
Public Class Methods
new(name, type = nil)
click to toggle source
# File lib/softlayer/ObjectMaskProperty.rb, line 23 def initialize(name, type = nil) @name = name @type = type @children = [] end
Public Instance Methods
add_child(new_child)
click to toggle source
# File lib/softlayer/ObjectMaskProperty.rb, line 49 def add_child(new_child) mergeable_child = @children.find { |existing_child| existing_child.can_merge_with? new_child } if mergeable_child mergeable_child.merge new_child else @children.push new_child end end
add_children(new_children)
click to toggle source
# File lib/softlayer/ObjectMaskProperty.rb, line 58 def add_children(new_children) new_children.each { |new_child| add_child(new_child) } end
can_merge_with?(other_property)
click to toggle source
# File lib/softlayer/ObjectMaskProperty.rb, line 45 def can_merge_with? (other_property) (self.name == other_property.name) && (self.type == other_property.type) end
merge(other_property)
click to toggle source
DANGER: assumes you've already checked can_merge_with? before calling this routine!
# File lib/softlayer/ObjectMaskProperty.rb, line 63 def merge(other_property) add_children other_property.children end
to_s()
click to toggle source
# File lib/softlayer/ObjectMaskProperty.rb, line 29 def to_s full_name = @name if @type && !@type.empty? full_name += "(#{@type})" end if @children.count == 1 full_name + ".#{@children[0].to_s}" elsif @children.count > 1 full_name + "[#{@children.collect { |child| child.to_s }.join(',')}]" else full_name end end