module PIM::AttributeTemplates

Constants

COLLECTION_TO_XML
DIMENSIONAL_TO_XML
ENUM_SET_TO_XML
GROUP_TO_XML
MULTI_DIMENSIONAL_TO_XML
PHYSICAL_FORMATTER
PHYSICAL_PARSER
PHYSICAL_TO_XML

Public Instance Methods

AdditionalCategory(additional_module_name, additional_category_name = nil) click to toggle source

A template for additional categorization attributes. Needs the name of the linked data model and an optional root category.

# File pim.rb, line 5225
def AdditionalCategory(additional_module_name, additional_category_name = nil)
  additional_module_name = additional_module_name.to_s
  additional_category_name = additional_category_name.to_s
  additional_module = PIM.get_module(additional_module_name)
  raise "Additional module '#{additional_module_name}' is not defined" if !additional_module
  if additional_category_name
    additional_category = query_module_category(additional_module, additional_category_name)
    raise "Category '#{additional_category_name}' is not defined in additional module '#{additional_module_name}'" if !additional_category
  end
  params = {
    :additional_module => additional_module_name,
    :additional_category => additional_category_name
  }
  service_name = additional_module.service_name
  params[:extension] = service_name unless PIM.is_empty?(service_name)
  return AttributeTemplate.new("AdditionalCategory", String, params)
end
Boolean(values = { :true => "True", :false => "False" }) click to toggle source

A template for “boolean” type values. Actually it works like the ‘Enum’ type, but only uses a different renderer in the editor:

  • When only one fixed value is specified, uses a “checkbox”

  • When multiple values are specified, uses “radiobuttons”

The default fixed values are simply “true” and “false”.

# File pim.rb, line 5346
def Boolean(values = { :true => "True", :false => "False" })
  check_options values, type: 'Boolean', param: 'values'
  params = { :values => values }
  params[:renderer] = 'SingleBoolean' if values.length == 1
  return AttributeTemplate.new("Boolean", String, params)
end
Codelist(codelist_name) click to toggle source
# File pim.rb, line 5369
def Codelist(codelist_name)
  return AttributeTemplate.new("Codelist", String, { :codelist => codelist_name })
end
CodelistSet(codelist_name) click to toggle source
# File pim.rb, line 5377
def CodelistSet(codelist_name)
  return AttributeTemplate.new("CodelistSet", Array, {
    :codelist => codelist_name,
    :to_xml => ENUM_SET_TO_XML,
    :xml_key => 'seq',
    :uniq => true
  })
end
Collection(value_attribute) click to toggle source

A template for a collection of values based on a composite attribute. This template will use a “table” renderer and thus is limited to non repeatable values inside the composite attribute. Uses “Array” for internal value representation.

# File pim.rb, line 5514
def Collection(value_attribute)
  attribute = data_module.attribute(value_attribute)
  raise "Attribute '#{value_attribute}' used in collection type is not defined" if !attribute
  raise "Attribute '#{value_attribute}' used in collection type must be of class Composite" if !(attribute.base_class <= Composite)
  return AttributeTemplate.new("Collection", Array, { :value_attribute => value_attribute })
end
Composite(*args) click to toggle source

Not actually a template, but a method to create a new Composite class which can be used as base class in attributes

# File pim.rb, line 5505
def Composite(*args)
  composite = PIM::Composite.new(*args)
  DataModuleObject.set_data_module(composite, data_module)
  return composite
end
Date(format = "mediumDate") click to toggle source

A template for date based values. Uses simple ISO 8601 date format as default.

# File pim.rb, line 5245
def Date(format = "mediumDate")
  return AttributeTemplate.new("Date", Date, { :format => format })
end
DateTime(format = "medium") click to toggle source

A template for date-time based values. Uses simple ISO 8601 date-time format as default.

# File pim.rb, line 5251
def DateTime(format = "medium")
  return AttributeTemplate.new("DateTime", DateTime, { :format => format })
end
Dimensional(*args) click to toggle source

A template for dimension based values. Uses “Hash” for internal value representation. The default ‘dimension_xml_key’ is “lang” due to “historical” reasons

# File pim.rb, line 5258
def Dimensional(*args)

  if args.length == 1
    value_class = String
    keys = args[0]
  elsif args.length == 2
    value_class = args[0]
    keys = args[1]
  else
    raise "Wrong number of arguments: Expected either value class and dimensional keys or only dimensional keys"
  end

  check_options keys, type: 'Dimensional', param: 'keys'
  return AttributeTemplate.new('Dimensional', Hash, {
    :keys => keys,
    :value_class => value_class,
    :dimension_xml_key => 'lang',
    :to_xml => DIMENSIONAL_TO_XML
  })

end
Document() click to toggle source

A template for document values. Uses a string based URL for internal value representation.

# File pim.rb, line 5363
def Document()
  return AttributeTemplate.new("Document", String, {
    :check_url => true
  })
end
DynamicEnum(dynamic_values_url) click to toggle source

A template for a single String value based on a dynamic list of values.

# File pim.rb, line 5337
def DynamicEnum(dynamic_values_url)
  return AttributeTemplate.new("Enum", String, { :values => {}, :dynamic_values_url => dynamic_values_url })
end
Enum(values) click to toggle source

A template for a single String value based on a fixed list of values.

# File pim.rb, line 5296
def Enum(values)
  check_options values, type: 'Enum', param: 'values'
  return AttributeTemplate.new("Enum", String, { :values => values })
end
EnumSet(value_attribute) click to toggle source

A template for a multiple String value based on a fixed list of values. Uses “Array” as base class. FIXME: Allow to specify option list and/or options directly!

# File pim.rb, line 5310
def EnumSet(value_attribute)
  attribute = data_module.attribute(value_attribute)
  raise "Attribute '#{value_attribute}' used in enum-set type is not defined" if !attribute
  raise "Attribute '#{value_attribute}' used in enum-set type must be of type Enum" if attribute.type_name != 'Enum'
  return AttributeTemplate.new('EnumSet', Array, {
    :value_attribute => value_attribute,
    :to_xml => ENUM_SET_TO_XML,
    :xml_key => 'seq',
    :uniq => true
  })
end
Group(value_attribute) click to toggle source

A template for repeatable groups of attributes based on a composite attribute. Like ‘Collection’, but allows repeatable values inside the composite attribute. Uses “Array” for internal value representation.

# File pim.rb, line 5524
def Group(value_attribute)
  attribute = data_module.attribute(value_attribute)
  raise "Attribute '#{value_attribute}' used in group type is not defined" if !attribute
  raise "Attribute '#{value_attribute}' used in group type must be of class Composite" if !(attribute.base_class <= Composite)
  return AttributeTemplate.new("Group", Array, { :value_attribute => value_attribute })
end
Image() click to toggle source

A template for image values. Uses a string based URL for internal value representation.

# File pim.rb, line 5355
def Image()
  return AttributeTemplate.new("Image", String, {
    :check_url => true
  })
end
MultiDimensional(key_members, value_members) click to toggle source

A template for multi dimension based values. Each parameter should be specified as Array of existing attributes

# File pim.rb, line 5544
def MultiDimensional(key_members, value_members)
  multi_dimensional = PIM::MultiDimensional.new(data_module, key_members, value_members)
  DataModuleObject.set_data_module(multi_dimensional, data_module)
  return multi_dimensional
end
MultiReference(value_attribute) click to toggle source
# File pim.rb, line 5531
def MultiReference(value_attribute)
  attribute = data_module.attribute(value_attribute)
  raise "Attribute '#{value_attribute}' used in multi-reference type is not defined" if !attribute
  raise "Attribute '#{value_attribute}' used in multi-reference type must be of class Composite" if !(attribute.base_class <= Composite)
  return AttributeTemplate.new("MultiReference", Array, { :value_attribute => value_attribute })
end
OpenCodelist(codelist_name) click to toggle source
# File pim.rb, line 5373
def OpenCodelist(codelist_name)
  return AttributeTemplate.new("OpenCodelist", String, { :codelist => codelist_name, :skip_values_validation => true })
end
OpenCodelistSet(codelist_name) click to toggle source
# File pim.rb, line 5386
def OpenCodelistSet(codelist_name)
  return AttributeTemplate.new("OpenCodelistSet", Array, {
    :codelist => codelist_name,
    :skip_values_validation => true,
    :to_xml => ENUM_SET_TO_XML,
    :xml_key => 'seq',
    :uniq => true
  })
end
OpenDimensional(value_class = String, keys = {}) click to toggle source

A template for dimension based values, but does not enforce the keys to exist in the fixed list of keys. Uses “Hash” for internal value representation. The default ‘dimension_xml_key’ is “lang” due to “historical” reasons FIXME: This type does not have a UI representation yet!

# File pim.rb, line 5284
def OpenDimensional(value_class = String, keys = {})
  check_options keys, type: 'OpenDimensional', param: 'keys' unless PIM.is_empty?(keys)
  return AttributeTemplate.new('OpenDimensional', Hash, {
    :keys => keys,
    :value_class => value_class,
    :skip_keys_validation => true,
    :dimension_xml_key => 'lang',
    :to_xml => DIMENSIONAL_TO_XML
  })
end
OpenEnum(values) click to toggle source

Like ‘Enum’, but does not enforce the value to exist in the fixed list of values.

# File pim.rb, line 5302
def OpenEnum(values)
  check_options values, type: 'OpenEnum', param: 'values' unless PIM.is_empty?(values)
  return AttributeTemplate.new("OpenEnum", String, { :values => values, :skip_values_validation => true })
end
OpenEnumSet(value_attribute) click to toggle source

Like ‘EnumSet’, but does not enforce the value to exist in the fixed list of values. FIXME: Allow to specify option list and/or options directly!

# File pim.rb, line 5324
def OpenEnumSet(value_attribute)
  attribute = data_module.attribute(value_attribute)
  raise "Attribute '#{value_attribute}' used in open-enum-set type is not defined" if !attribute
  raise "Attribute '#{value_attribute}' used in open-enum-set type must be of type OpenEnum" if attribute.type_name != 'OpenEnum'
  return AttributeTemplate.new('OpenEnumSet', Array, {
    :value_attribute => value_attribute,
    :to_xml => ENUM_SET_TO_XML,
    :xml_key => 'seq',
    :uniq => true
  })
end
Password() click to toggle source
# File pim.rb, line 5550
def Password()
  return AttributeTemplate.new("Password", String)
end
Physical(units, *group_names) click to toggle source

A template for single physical values. Uses “Hash” for internal value representation. Values are parsed from and formatted to a string containing the value itself and it’s physical unit.

# File pim.rb, line 5480
def Physical(units, *group_names)
  check_options units, type: 'Physical', param: 'keys'
  params = {
    :keys => units,
    :value_class => Float,
    :formatter => PHYSICAL_FORMATTER,
    :parser => PHYSICAL_PARSER,
    :maxLength => 1,
    :to_xml => PHYSICAL_TO_XML
  }
  if group_names.size == 1 and is_array?(group_names[0])
    group_names = group_names[0]
  end
  params[:keys_option_groups] = group_names unless group_names.empty?
  return AttributeTemplate.new('Physical', Hash, params)
end
PhysicalInteger(units, *group_names) click to toggle source

Same as Physical except the value_class is an Integer

# File pim.rb, line 5498
def PhysicalInteger(units, *group_names)
  attributeTemplate = Physical(units, group_names)
  attributeTemplate.param(:value_class, Integer)
  attributeTemplate
end
SingleReference() click to toggle source
# File pim.rb, line 5538
def SingleReference()
  return AttributeTemplate.new("SingleReference", String)
end