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

new() click to toggle source
# 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

[](index) click to toggle source

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(level) click to toggle source

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
clear() click to toggle source

Remove all AlertLevelDefinition objects from the list.

# File lib/taskjuggler/AlertLevelDefinitions.rb, line 45
def clear
  @levels = []
  @modified = true
end
indexByColor(color) click to toggle source

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
indexById(id) click to toggle source

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
indexByName(name) click to toggle source

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
map(&block) click to toggle source

Pass map call to @levels.

# File lib/taskjuggler/AlertLevelDefinitions.rb, line 92
def map(&block)
  @levels.map(&block)
end
modified?() click to toggle source

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
to_tjp() click to toggle source

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