class OmfEc::Property

This class describes a Property, which is part of a Prototype

Attributes

bindingRef[R]
idref[R]
isBound[R]
unit[R]
value[R]

Public Class Methods

from_xml(defRoot) click to toggle source

Unmarshall a Property instance from an XML tree.

  • defRoot = the root of the XML tree describing the Property

Return

a new Property instance initialized with the information from the XML tree

# File lib/omf_ec/property.rb, line 36
def self.from_xml(defRoot)
  if (defRoot.name != "property")
    raise "Property definition needs to start with an 'property' element"
  end
  idref = defRoot.attributes['idref']
  obj = unit = nil
  isBinding = false
  defRoot.elements.each { |el|
    case el.name
    when 'binding'
      obj = el.attribute['idref']
      isBinding = true
    when 'value'
      obj = el.text
      unit = el.attribute['unit']
    else
      warn "Ignoring element '#{el.name}'"
    end
  }
  if isBinding then warn "NOT IMPLEMENTED: Resolving bindings from XML streams" end
  p = self.new(idred, obj, unit, isBinding)
  return p
end
new(idref, obj = nil, unit = nil, isBinding = false) click to toggle source

Create a new Property instance

  • idref = Reference to property in {@link AppDefinition}

  • obj = Value or property binding to establish value of property

  • unit = Unit of value

  • isBinding = If true “obj” is a property reference, otherwise it’s a value

# File lib/omf_ec/property.rb, line 70
def initialize(idref, obj = nil, unit = nil, isBinding = false)
  @idref = idref
  @unit = unit
  if isBinding
    @bindingRef = obj
  else
    @value = obj
  end
  @isBound = isBinding
end

Public Instance Methods

to_xml() click to toggle source

Return the definition of this Property as an XML element

Return

a XML element describing this Property

# File lib/omf_ec/property.rb, line 86
def to_xml
  a = REXML::Element.new("property")
  a.add_attribute("name", idref)
  if isBound
    a.add_element("binding", {"idref" => bindingRef})
  elsif value != nil
    v = a.add_element("value")
    v.text = value
    if (unit != nil)
      v.add_attribute("unit", unit)
    end
  else
    Log.warn("NOT IMPLEMENTED: check for default value in app definition")
  end
  return a
end