class PIM::Composite

Public Class Methods

as_json() click to toggle source
# File pim.rb, line 3628
def self.as_json
  hash = {
    :baseClass => Struct,
  }
  hash[:members] = []
  self.members.each do |m|
    hash[:members] << m
  end
  hash
end
from_json(json) click to toggle source
# File pim.rb, line 3623
def self.from_json json
  composite = self.new json
  composite
end
name=(name) click to toggle source
# File pim.rb, line 3666
def self.name= name
  @name = name
end
new(*args) click to toggle source
# File pim.rb, line 3670
def initialize *args

  # Initialize with specified arguments
  if args.size == 1 and PIM::Utils.is_array?(args[0])
    from_array args[0]
  elsif args.size == 1 and PIM::Utils.is_hash?(args[0])
    from_hash args[0]
  elsif args.size == 1 and args[0].is_a? String
    from_json args[0]
  elsif !args.empty?
    from_array args
  end

  # Create objects for empty multi value attributes
  members.each do |m|
    next if self[m]
    attribute = data_module.attribute(m)
    if attribute and attribute.is_multivalue?
      value = attribute.new
      self[m] = value
    end
  end

end
params() click to toggle source
# File pim.rb, line 3639
def self.params
  @params ||= {
    :type_name => "Composite",
    :is_multivalue => true
  }.freeze
  @params
end
sub_attributes() click to toggle source
# File pim.rb, line 3647
def self.sub_attributes
  self.members
end
to_s() click to toggle source
Calls superclass method
# File pim.rb, line 3662
def self.to_s
  self.name || @name || super
end
validate_each(old_value, new_value, &validate_sub_attribute) click to toggle source
# File pim.rb, line 3651
def self.validate_each old_value, new_value, &validate_sub_attribute

  # Apply rules for each member
  members.each do |m|
    sub_old_value = old_value ? ({ m => PIM.get_value(old_value, m) }) : nil
    sub_new_value = new_value ? ({ m => PIM.get_value(new_value, m) }) : nil
    validate_sub_attribute.call m, sub_old_value, sub_new_value, nil, m
  end

end

Public Instance Methods

as_json(include_empty = false) click to toggle source
# File pim.rb, line 3709
def as_json include_empty = false
  return nil if not include_empty and empty?
  hash = {}
  members.each do |m|
    value = data_module.value_as_json m, self[m]
    hash[m.to_s] = value if include_empty or not value.nil?
  end
  hash
end
data_module() click to toggle source
# File pim.rb, line 3695
def data_module
  self.class.data_module
end
dup() click to toggle source
Calls superclass method
# File pim.rb, line 3699
def dup
  duplicate = super
  duplicate.members.each do |m|
    value = duplicate[m]
    value = PIM.dup_value(value)
    duplicate[m] = value
  end
  duplicate
end
empty?() click to toggle source
# File pim.rb, line 3719
def empty?
  members.each do |m|
    value = self[m]
    next if value.nil?
    if value.respond_to?(:empty?)
      next if value.empty?
    end
    return false
  end
  true
end
inspect()
Alias for: to_s
to_h() click to toggle source
# File pim.rb, line 3735
def to_h
  Hash[each_pair.to_a]
end
to_hash() click to toggle source
# File pim.rb, line 3731
def to_hash
  Hash[each_pair.to_a]
end
to_s() click to toggle source
# File pim.rb, line 3739
def to_s
  to_h.to_s
end
Also aliased as: inspect