Class: TaskJuggler::AlertLevelDefinitions
- Defined in:
- lib/taskjuggler/AlertLevelDefinitions.rb
Overview
This class holds a list of AlertLevelDefinition objects. There are 3 default levels. If they are changed, the :modified flag will indicate this.
Instance Method Summary collapse
-
#[](index) ⇒ Object
Return the AlertLevelDefinition at index or nil if index is out of range.
-
#add(level) ⇒ Object
Add a new AlertLevelDefinition.
-
#clear ⇒ Object
Remove all AlertLevelDefinition objects from the list.
-
#indexByColor(color) ⇒ Object
Try to match color to a defined alert level ID and return the index of it.
-
#indexById(id) ⇒ Object
Try to match id to a defined alert level ID and return the index of it.
-
#indexByName(name) ⇒ Object
Try to match name to a defined alert level ID and return the index of it.
-
#initialize ⇒ AlertLevelDefinitions
constructor
A new instance of AlertLevelDefinitions.
-
#map(&block) ⇒ Object
Pass map call to @levels.
-
#modified? ⇒ Boolean
Return true if the alert levels are no longer the default ones, otherwise return false.
-
#to_tjp ⇒ Object
Return the definition of the alert levels in TJP syntax.
Constructor Details
#initialize ⇒ AlertLevelDefinitions
Returns a new instance of AlertLevelDefinitions.
33 34 35 36 37 38 39 40 41 42 |
# 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 |
Instance Method Details
#[](index) ⇒ Object
Return the AlertLevelDefinition at index or nil if index is out of range.
87 88 89 |
# File 'lib/taskjuggler/AlertLevelDefinitions.rb', line 87 def [](index) @levels[index] end |
#add(level) ⇒ Object
Add a new AlertLevelDefinition.
51 52 53 54 55 56 57 58 59 |
# 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 ⇒ Object
Remove all AlertLevelDefinition objects from the list.
45 46 47 48 |
# File 'lib/taskjuggler/AlertLevelDefinitions.rb', line 45 def clear @levels = [] @modified = true end |
#indexByColor(color) ⇒ Object
Try to match color to a defined alert level ID and return the index of it. If no level is found, nil is returned.
81 82 83 |
# File 'lib/taskjuggler/AlertLevelDefinitions.rb', line 81 def indexByColor(color) @levels.index { |level| color == level.color } end |
#indexById(id) ⇒ Object
Try to match id to a defined alert level ID and return the index of it. If no level is found, nil is returned.
69 70 71 |
# File 'lib/taskjuggler/AlertLevelDefinitions.rb', line 69 def indexById(id) @levels.index { |level| id == level.id } end |
#indexByName(name) ⇒ Object
Try to match name to a defined alert level ID and return the index of it. If no level is found, nil is returned.
75 76 77 |
# File 'lib/taskjuggler/AlertLevelDefinitions.rb', line 75 def indexByName(name) @levels.index { |level| name == level.name } end |
#map(&block) ⇒ Object
Pass map call to @levels.
92 93 94 |
# File 'lib/taskjuggler/AlertLevelDefinitions.rb', line 92 def map(&block) @levels.map(&block) end |
#modified? ⇒ Boolean
Return true if the alert levels are no longer the default ones, otherwise return false.
63 64 65 |
# File 'lib/taskjuggler/AlertLevelDefinitions.rb', line 63 def modified? @modified end |
#to_tjp ⇒ Object
Return the definition of the alert levels in TJP syntax.
97 98 99 |
# File 'lib/taskjuggler/AlertLevelDefinitions.rb', line 97 def to_tjp "alertlevels #{@levels.join(",\n")}" end |