class PIM::Section

Attributes

attributes[R]
label[RW]
model_defined[RW]
modification_status[RW]
name[R]
preview_image_attribute[RW]
section_attribute_status[RW]
sort_order[RW]
width[RW]

Public Class Methods

new(name, label, attributes = {}) click to toggle source
# File pim.rb, line 6957
def initialize name, label, attributes = {}, width = nil, preview_image_attribute = nil
  @model_defined = true
  @name = name
  @label = label
  @attributes = attributes
  @width = width
  @section_attribute_status = {}
  @sort_order = nil
  @preview_image_attribute = preview_image_attribute
end

Public Instance Methods

==(other) click to toggle source
# File pim.rb, line 6991
def ==(other)
  self.class === other and
    PIM::Utils.is_equal?(name.to_s, other.name.to_s) and
    PIM::Utils.is_equal?(label.to_s, other.label.to_s) and
    PIM::Utils.is_equal?(attributes, other.attributes) and
    PIM::Utils.is_equal?(modification_status, other.modification_status) and
    PIM::Utils.is_equal?(section_attribute_status, other.section_attribute_status) and
    PIM::Utils.is_equal?(sort_order, other.sort_order)
end
add_attribute(attribute) click to toggle source
# File pim.rb, line 6968
def add_attribute attribute
  attribute = PIM::Utils.to_sym(attribute)
  return if not data_module.all_attributes.include?(attribute)
  if attributes.include?(attribute)
    if @section_attribute_status[attribute] != :REMOVED
      PIM.log_warn("Attribute '#{attribute}' already defined in section #{name}")
    else
      @section_attribute_status[attribute] = :ADDED
    end
  else
    attributes[PIM::Utils.to_sym(attribute)] = SectionAttribute.new(attribute)
    @section_attribute_status[attribute] = :ADDED
  end
end
as_json(opts = {}) click to toggle source
# File pim.rb, line 7001
def as_json opts = {}

  if PIM::Utils.has_opt?(opts, :format, :compact)

    hash = {
      :name => (@name ? @name.to_s : nil),
      :label => @label
    }

    attributes = {}

    # Add attributes by sort order first
    if @sort_order
      @sort_order.each do |attribute_name|
        attribute_name = PIM::Utils.to_sym(attribute_name)
        attribute = @attributes[attribute_name]
        next if not attribute or @section_attribute_status[attribute_name] == :REMOVED
        json = attribute.as_json(opts)
        attributes[attribute_name] = json if json
      end
    end

    @attributes.each do |attribute_name, attribute|
      attribute_name = PIM::Utils.to_sym(attribute_name)
      next if attributes.include?(attribute_name) or @section_attribute_status[attribute_name] == :REMOVED
      json = attribute.as_json(opts)
      attributes[attribute_name] = json if json
    end

    hash[:attributes] = attributes.values
    hash[:width] = @width unless @width.nil?
    hash[:preview_image_attribute] = @preview_image_attribute unless @preview_image_attribute.nil?

  else

    hash = {
      :name => (@name ? @name.to_s : nil),
      :label => @label,
      :attributes => PIM::Utils.as_json(@attributes.values),
      :model_defined => @model_defined
    }
    hash[:modification_status] = @modification_status if @modification_status
    hash[:attribute_status] = PIM::Utils.as_json(@section_attribute_status) if !PIM::Utils.is_empty?(@section_attribute_status)
    hash[:sort_order] = PIM::Utils.as_json(@sort_order) if @sort_order
    hash[:width] = @width unless @width.nil?
    hash[:preview_image_attribute] = @preview_image_attribute unless @preview_image_attribute.nil?

  end

  hash

end
remove_attribute(attribute) click to toggle source
# File pim.rb, line 6983
def remove_attribute attribute
  if attributes.include?(attribute)
    @section_attribute_status[attribute] = :REMOVED
  else
    PIM.log_warn("Attribute '#{attribute}' to remove is not defined in section #{name}")
  end
end