Class: OmfEc::Property

Inherits:
Object
  • Object
show all
Defined in:
omf_ec/lib/omf_ec/property.rb

Overview

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

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Property) initialize(idref, obj = nil, unit = nil, isBinding = false)

Create a new Property instance

  • idref = Reference to property in 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



70
71
72
73
74
75
76
77
78
79
# File 'omf_ec/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

Instance Attribute Details

- (Object) bindingRef (readonly)

Returns the value of attribute bindingRef



60
61
62
# File 'omf_ec/lib/omf_ec/property.rb', line 60

def bindingRef
  @bindingRef
end

- (Object) idref (readonly)

Returns the value of attribute idref



60
61
62
# File 'omf_ec/lib/omf_ec/property.rb', line 60

def idref
  @idref
end

- (Object) isBound (readonly)

Returns the value of attribute isBound



60
61
62
# File 'omf_ec/lib/omf_ec/property.rb', line 60

def isBound
  @isBound
end

- (Object) unit (readonly)

Returns the value of attribute unit



60
61
62
# File 'omf_ec/lib/omf_ec/property.rb', line 60

def unit
  @unit
end

- (Object) value (readonly)

Returns the value of attribute value



60
61
62
# File 'omf_ec/lib/omf_ec/property.rb', line 60

def value
  @value
end

Class Method Details

+ (Object) from_xml(defRoot)

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



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'omf_ec/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

Instance Method Details

- (Object) to_xml

Return the definition of this Property as an XML element

Return

a XML element describing this Property



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'omf_ec/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