class TaskJuggler::AlertLevelDefinitions
This class holds a list of AlertLevelDefinition
objects. There are 3 default levels. If they are changed, the :modified flag will indicate this.
Public Class Methods
# File lib/taskjuggler/AlertLevelDefinitions.rb, line 33 def initialize # By default, we have a green, a yellow and a red level defined. @levels = [] add(AlertLevelDefinition.new('green', 'Green', '#008000')) add(AlertLevelDefinition.new('yellow', 'Yellow', '#BEA800')) add(AlertLevelDefinition.new('red', 'Red', '#C00000')) # Since those are the default values, we reset the modified flag. @modified = false end
Public Instance Methods
Return the AlertLevelDefinition
at index or nil if index is out of range.
# File lib/taskjuggler/AlertLevelDefinitions.rb, line 87 def [](index) @levels[index] end
Add a new AlertLevelDefinition
.
# File lib/taskjuggler/AlertLevelDefinitions.rb, line 51 def add(level) raise ArgumentError unless level.is_a?(AlertLevelDefinition) if indexById(level.id) || indexByName(level.name) raise ArgumentError, "ID and name must be unique" end @levels << level @modified = true end
Remove all AlertLevelDefinition
objects from the list.
# File lib/taskjuggler/AlertLevelDefinitions.rb, line 45 def clear @levels = [] @modified = true end
Try to match color to a defined alert level ID and return the index of it. If no level is found, nil is returned.
# File lib/taskjuggler/AlertLevelDefinitions.rb, line 81 def indexByColor(color) @levels.index { |level| color == level.color } end
Try to match id to a defined alert level ID and return the index of it. If no level is found, nil is returned.
# File lib/taskjuggler/AlertLevelDefinitions.rb, line 69 def indexById(id) @levels.index { |level| id == level.id } end
Try to match name to a defined alert level ID and return the index of it. If no level is found, nil is returned.
# File lib/taskjuggler/AlertLevelDefinitions.rb, line 75 def indexByName(name) @levels.index { |level| name == level.name } end
Pass map call to @levels.
# File lib/taskjuggler/AlertLevelDefinitions.rb, line 92 def map(&block) @levels.map(&block) end
Return true if the alert levels are no longer the default ones, otherwise return false.
# File lib/taskjuggler/AlertLevelDefinitions.rb, line 63 def modified? @modified end
Return the definition of the alert levels in TJP syntax.
# File lib/taskjuggler/AlertLevelDefinitions.rb, line 97 def to_tjp "alertlevels #{@levels.join(",\n")}" end