Class: TaskJuggler::AttributeBase
- Defined in:
- lib/taskjuggler/AttributeBase.rb
Overview
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.
Direct Known Subclasses
AccountAttribute, BooleanAttribute, DateAttribute, DurationAttribute, FixnumAttribute, FloatAttribute, LimitsAttribute, ListAttributeBase, LogicalExpressionAttribute, PropertyAttribute, RealFormatAttribute, ReferenceAttribute, RichTextAttribute, ShiftAssignmentsAttribute, StringAttribute, SymbolAttribute, WorkingHoursAttribute
Constant Summary collapse
- @@mode =
The mode is flag that controls how value assignments affect the flags.
0
Instance Attribute Summary collapse
-
#inherited ⇒ Object
readonly
Returns the value of attribute inherited.
-
#property ⇒ Object
readonly
Returns the value of attribute property.
-
#provided ⇒ Object
readonly
Returns the value of attribute provided.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.isList? ⇒ Boolean
We overwrite this for ListAttributeBase.
-
.mode ⇒ Object
Return the current attribute setting mode.
-
.setMode(mode) ⇒ Object
Change the @@mode.
Instance Method Summary collapse
-
#get ⇒ Object
(also: #value)
Return the attribute value.
-
#id ⇒ Object
Return the ID of the attribute.
-
#inherit(value) ⇒ Object
Call this function to inherit value from the parent property.
-
#initialize(property, type, container) ⇒ AttributeBase
constructor
Create a new AttributeBase object.
- #isList? ⇒ Boolean
-
#name ⇒ Object
Return the name of the attribute.
-
#nil? ⇒ Boolean
Check whether the value is uninitialized or nil.
-
#reset ⇒ Object
Reset the attribute value to the default value.
-
#set(value) ⇒ Object
Set the value of the attribute.
- #to_num ⇒ Object
- #to_rti(query) ⇒ Object
-
#to_s(query = nil) ⇒ Object
Return the value as String.
- #to_sort ⇒ Object
-
#to_tjp ⇒ Object
Return the value in TJP file syntax.
Constructor Details
#initialize(property, type, container) ⇒ AttributeBase
Create a new AttributeBase object. type specifies the specific type of the object. property is the PropertyTreeNode object this attribute belongs to.
38 39 40 41 42 43 44 |
# File 'lib/taskjuggler/AttributeBase.rb', line 38 def initialize(property, type, container) @type = type @property = property @container = container reset end |
Instance Attribute Details
#inherited ⇒ Object (readonly)
Returns the value of attribute inherited.
30 31 32 |
# File 'lib/taskjuggler/AttributeBase.rb', line 30 def inherited @inherited end |
#property ⇒ Object (readonly)
Returns the value of attribute property.
30 31 32 |
# File 'lib/taskjuggler/AttributeBase.rb', line 30 def property @property end |
#provided ⇒ Object (readonly)
Returns the value of attribute provided.
30 31 32 |
# File 'lib/taskjuggler/AttributeBase.rb', line 30 def provided @provided end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
30 31 32 |
# File 'lib/taskjuggler/AttributeBase.rb', line 30 def type @type end |
Class Method Details
.isList? ⇒ Boolean
We overwrite this for ListAttributeBase.
128 129 130 |
# File 'lib/taskjuggler/AttributeBase.rb', line 128 def AttributeBase::isList? false end |
.mode ⇒ Object
Return the current attribute setting mode.
72 73 74 |
# File 'lib/taskjuggler/AttributeBase.rb', line 72 def AttributeBase.mode @@mode end |
.setMode(mode) ⇒ Object
Change the @@mode. 0 means values are provided, 1 means values are inherited, any other value means calculated.
78 79 80 |
# File 'lib/taskjuggler/AttributeBase.rb', line 78 def AttributeBase.setMode(mode) @@mode = mode end |
Instance Method Details
#get ⇒ Object Also known as: value
Return the attribute value.
107 108 109 |
# File 'lib/taskjuggler/AttributeBase.rb', line 107 def get @container.instance_variable_get(('@' + type.id).intern) end |
#id ⇒ Object
Return the ID of the attribute.
83 84 85 |
# File 'lib/taskjuggler/AttributeBase.rb', line 83 def id type.id end |
#inherit(value) ⇒ Object
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.
66 67 68 69 |
# File 'lib/taskjuggler/AttributeBase.rb', line 66 def inherit(value) @inherited = true @container.instance_variable_set(('@' + type.id).intern, value.deep_clone) end |
#isList? ⇒ Boolean
123 124 125 |
# File 'lib/taskjuggler/AttributeBase.rb', line 123 def isList? false end |
#name ⇒ Object
Return the name of the attribute.
88 89 90 |
# File 'lib/taskjuggler/AttributeBase.rb', line 88 def name type.name end |
#nil? ⇒ Boolean
Check whether the value is uninitialized or nil.
115 116 117 118 119 120 121 |
# File 'lib/taskjuggler/AttributeBase.rb', line 115 def nil? if (v = get).is_a?(Array) v.empty? else v.nil? end end |
#reset ⇒ Object
Reset the attribute value to the default value.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/taskjuggler/AttributeBase.rb', line 47 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) ⇒ Object
Set the value of the attribute. Depending on the mode we are in, the flags are updated accordingly.
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/taskjuggler/AttributeBase.rb', line 94 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 ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/taskjuggler/AttributeBase.rb', line 137 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) ⇒ Object
157 158 159 |
# File 'lib/taskjuggler/AttributeBase.rb', line 157 def to_rti(query) get.is_a?(RichTextIntermediate) ? !value : nil end |
#to_s(query = nil) ⇒ Object
Return the value as String.
133 134 135 |
# File 'lib/taskjuggler/AttributeBase.rb', line 133 def to_s(query = nil) get.to_s end |
#to_sort ⇒ Object
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/taskjuggler/AttributeBase.rb', line 146 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 ⇒ Object
Return the value in TJP file syntax.
162 163 164 |
# File 'lib/taskjuggler/AttributeBase.rb', line 162 def to_tjp @type.id + " " + get.to_s end |