class TaskJuggler::AttributeBase

This class is the base for all property attribute types. Each property can have multiple attributes of different type. For each type, there must be a special Ruby class. Each of these classes must be derived from this class. The class holds information like a reference to the property that owns the attribute and the type of the attribute.

The class can track wheter the attribute value was provided by the project file, inherited from another property or computed during scheduling.

Attributes that are of an inherited type will be copied from a parent property or the global scope.

Attributes

inherited[R]
property[R]
provided[R]
type[R]

Public Class Methods

isList?() click to toggle source

We overwrite this for ListAttributeBase.

# File lib/taskjuggler/AttributeBase.rb, line 127
def AttributeBase::isList?
  false
end
mode() click to toggle source

Return the current attribute setting mode.

# File lib/taskjuggler/AttributeBase.rb, line 71
def AttributeBase.mode
  @@mode
end
new(property, type, container) click to toggle source

Create a new AttributeBase object. type specifies the specific type of the object. property is the PropertyTreeNode object this attribute belongs to.

# File lib/taskjuggler/AttributeBase.rb, line 37
def initialize(property, type, container)
  @type = type
  @property = property
  @container = container

  reset
end
setMode(mode) click to toggle source

Change the @@mode. 0 means values are provided, 1 means values are inherited, any other value means calculated.

# File lib/taskjuggler/AttributeBase.rb, line 77
def AttributeBase.setMode(mode)
  @@mode = mode
end

Public Instance Methods

get() click to toggle source

Return the attribute value.

# File lib/taskjuggler/AttributeBase.rb, line 106
def get
  @container.instance_variable_get(('@' + type.id).intern)
end
Also aliased as: value
id() click to toggle source

Return the ID of the attribute.

# File lib/taskjuggler/AttributeBase.rb, line 82
def id
  type.id
end
inherit(value) click to toggle source

Call this function to inherit value from the parent property. It is very important that the values are deep copied as they may be modified later on.

# File lib/taskjuggler/AttributeBase.rb, line 65
def inherit(value)
  @inherited = true
  @container.instance_variable_set(('@' + type.id).intern, value.deep_clone)
end
isList?() click to toggle source
# File lib/taskjuggler/AttributeBase.rb, line 122
def isList?
  false
end
name() click to toggle source

Return the name of the attribute.

# File lib/taskjuggler/AttributeBase.rb, line 87
def name
  type.name
end
nil?() click to toggle source

Check whether the value is uninitialized or nil.

# File lib/taskjuggler/AttributeBase.rb, line 114
def nil?
  if (v = get).is_a?(Array)
    v.empty?
  else
    v.nil?
  end
end
reset() click to toggle source

Reset the attribute value to the default value.

# File lib/taskjuggler/AttributeBase.rb, line 46
def reset
  @inherited = false
  # Flag that marks whether the value of this attribute was provided by the
  # user (in contrast to being calculated).
  @provided = false
  # If type is an AttributeDefinition, create the initial value according
  # to the specified default for this type. Otherwise type is the initial
  # value.
  if @type.is_a?(AttributeDefinition)
    @container.instance_variable_set(('@' + type.id).intern,
                                     @type.default.deep_clone)
  else
    @container.instance_variable_set(('@' + type.id).intern, @type)
  end
end
set(value) click to toggle source

Set the value of the attribute. Depending on the mode we are in, the flags are updated accordingly.

# File lib/taskjuggler/AttributeBase.rb, line 93
def set(value)
  case @@mode
    when 0
      @provided = true
    when 1
      @inherited = true
  end
  # Store the value in an instance variable in the PropertyTreeNode or
  # ScenarioData object referred to by @container.
  @container.instance_variable_set(('@' + type.id).intern, value)
end
to_num() click to toggle source
# File lib/taskjuggler/AttributeBase.rb, line 136
def to_num
  v = get
  if v.is_a?(Fixnum) || v.is_a?(Bignum) || v.is_a?(Float)
    v
  else
    nil
  end
end
to_rti(query) click to toggle source
# File lib/taskjuggler/AttributeBase.rb, line 156
def to_rti(query)
  get.is_a?(RichTextIntermediate) ? !value : nil
end
to_s(query = nil) click to toggle source

Return the value as String.

# File lib/taskjuggler/AttributeBase.rb, line 132
def to_s(query = nil)
  get.to_s
end
to_sort() click to toggle source
# File lib/taskjuggler/AttributeBase.rb, line 145
def to_sort
  v = get
  if v.is_a?(Fixnum) || v.is_a?(Bignum) || v.is_a?(Float)
    v
  elsif v.respond_to?('to_s')
    v.to_s
  else
    nil
  end
end
to_tjp() click to toggle source

Return the value in TJP file syntax.

# File lib/taskjuggler/AttributeBase.rb, line 161
def to_tjp
  @type.id + " " + get.to_s
end
value()

For legacy purposes we provide another name for get().

Alias for: get