Module: OmfEc::CreatePropertiesModule

Defined in:
omf_ec/lib/omf_ec/property.rb

Overview

This module defines the methods used to create new Properties when defining Prototypes/Applications in Experiments

Instance Method Summary (collapse)

Instance Method Details

- (Object) addProperties(properties)

Add a list of properties described in a hash table where key is the property name and the value its value. If value starts with “$”, value is interpreted as the name of another property to bind to.

  • properties = a Hash describing a set of properties



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'omf_ec/lib/omf_ec/property.rb', line 141

def addProperties(properties)
  if properties != nil
    if properties.kind_of?(Hash)
      properties.each {|k, v|
        if v.kind_of?(Symbol)
          v = v.to_s
        end
        if v.kind_of?(String) && v[0] == ?$
          # is binding
          bindProperty(k, v[1..-1])
        else
          setProperty(k, v)
        end
      }
    elsif properties.kind_of? Array
      properties.each {|p|
        if ! p.kind_of? OmfEc::Property
          raise "Propertie array needs to contain Property, but is '" \
            + p.class.to_s + "'."
        end
        @properties += [p]
      }
    else
      raise "Properties declarations needs to be a Hash or Array, but is '" \
        + properties.class.to_s + "'."
    end

  end
end

- (Object) bindProperty(propName, propRef = propName)

Bind the value of a property to another property in the context

  • propName = name of application property

  • propRef = Property to bind to (default = 'propName')



128
129
130
131
# File 'omf_ec/lib/omf_ec/property.rb', line 128

def bindProperty(propName, propRef = propName)
  prop = OmfEc::Property.new(propName, propRef, nil, true)
  @properties += [prop]
end

- (Object) setProperty(propName, value, unit = nil)

Set a property of the application to a specific value

  • propName = Name of the application property

  • value = Value of property

  • unit = optional, unit for this Property



117
118
119
120
# File 'omf_ec/lib/omf_ec/property.rb', line 117

def setProperty(propName, value, unit = nil)
  prop = OmfEc::Property.new(propName, value, unit)
  @properties += [prop]
end