Class: TaskJuggler::ScoreboardInterval
- Defined in:
- lib/taskjuggler/Interval.rb
Overview
This class describes an interval of a scoreboard. The start and end of the interval are stored as indexes but can always be converted back to TjTime objects if needed.
Instance Attribute Summary collapse
-
#sbStart ⇒ Object
readonly
Returns the value of attribute sbStart.
-
#slotDuration ⇒ Object
readonly
Returns the value of attribute slotDuration.
Attributes inherited from Interval
Instance Method Summary collapse
-
#duration ⇒ Object
Return the duration of the ScoreboardInterval.
-
#end=(arg) ⇒ Object
Assign the start of the interval.
-
#endDate ⇒ Object
Return the interval end as TjTime object.
-
#initialize(*args) ⇒ ScoreboardInterval
constructor
Create a new ScoreboardInterval.
-
#start=(arg) ⇒ Object
Assign the start of the interval.
-
#startDate ⇒ Object
Return the interval start as TjTime object.
-
#to_s ⇒ Object
Turn the ScoreboardInterval into a human readable form.
Methods inherited from Interval
#<=>, #==, #combine, #contains?, #intersection, #overlaps?
Constructor Details
#initialize(*args) ⇒ ScoreboardInterval
Create a new ScoreboardInterval. args can be three different kind of arguments.
sbStart must be a TjTime of the scoreboard start slotDuration must be the duration of the scoreboard slots in seconds a and b should be TjTime or Integer objects that describe the start and end time or index of the interval.
TimeInterval.new(iv) TimeInterval.new(sbStart, slotDuration, a) TimeInterval.new(sbStart, slotDuration, a, b)
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/taskjuggler/Interval.rb', line 176 def initialize(*args) case args.length when 1 # If there is only one argument, it must be a ScoreboardInterval. if args[0].is_a?(ScoreboardInterval) @sbStart = args[0].sbStart @slotDuration = args[0].slotDuration # Just one argument, a TimeInterval super(args[0].start, args[0].end) else raise ArgumentError, "Illegal argument 1: #{args[0].class}" end when 3 @sbStart = args[0] @slotDuration = args[1] # If the third argument is a date we convert it to a scoreboard index. args[2] = dateToIndex(args[2]) if args[2].is_a?(TjTime) if args[2].is_a?(Integer) super(args[2], args[2]) else raise ArgumentError, "Illegal argument 3: #{args[0].class}" end when 4 @sbStart = args[0] @slotDuration = args[1] # If the third and forth arguments are a date we convert them to a # scoreboard index. args[2] = dateToIndex(args[2]) if args[2].is_a?(TjTime) args[3] = dateToIndex(args[3]) if args[3].is_a?(TjTime) if !(args[2].is_a?(Integer)) raise ArgumentError, "Interval start must be an index or TjTime, " + "not a #{args[2].class}" end if !(args[3].is_a?(Integer)) raise ArgumentError, "Interval end must be an index or TjTime, " + "not a #{args[3].class}" end super(args[2], args[3]) else raise ArgumentError, "Wrong number of arguments: #{args.length}" end unless @sbStart.is_a?(TjTime) raise ArgumentError, "sbStart must be a TjTime object, not a" + "#{@sbStart.class}" end unless @slotDuration.is_a?(Integer) raise ArgumentError, "slotDuration must be an Integer, not a " + "#{@slotDuration.class}" end end |
Instance Attribute Details
#sbStart ⇒ Object (readonly)
Returns the value of attribute sbStart.
162 163 164 |
# File 'lib/taskjuggler/Interval.rb', line 162 def sbStart @sbStart end |
#slotDuration ⇒ Object (readonly)
Returns the value of attribute slotDuration.
162 163 164 |
# File 'lib/taskjuggler/Interval.rb', line 162 def slotDuration @slotDuration end |
Instance Method Details
#duration ⇒ Object
Return the duration of the ScoreboardInterval.
268 269 270 |
# File 'lib/taskjuggler/Interval.rb', line 268 def duration indexToDate(@end) - indexToDate(@start) end |
#end=(arg) ⇒ Object
Assign the start of the interval. arg
can be an Integer or TjTime object.
246 247 248 249 250 251 252 253 254 255 |
# File 'lib/taskjuggler/Interval.rb', line 246 def end=(arg) case arg when Integer @end = arg when TjTime @end = dateToIndex(arg) else raise ArgumentError, "Unsupported class #{arg.class}" end end |
#endDate ⇒ Object
Return the interval end as TjTime object.
263 264 265 |
# File 'lib/taskjuggler/Interval.rb', line 263 def endDate indexToDate(@end) end |
#start=(arg) ⇒ Object
Assign the start of the interval. arg
can be an Integer or TjTime object.
233 234 235 236 237 238 239 240 241 242 |
# File 'lib/taskjuggler/Interval.rb', line 233 def start=(arg) case arg when Integer @start = arg when TjTime @start = dateToIndex(arg) else raise ArgumentError, "Unsupported class #{arg.class}" end end |
#startDate ⇒ Object
Return the interval start as TjTime object.
258 259 260 |
# File 'lib/taskjuggler/Interval.rb', line 258 def startDate indexToDate(@start) end |
#to_s ⇒ Object
Turn the ScoreboardInterval into a human readable form.
273 274 275 |
# File 'lib/taskjuggler/Interval.rb', line 273 def to_s indexToDate(@start).to_s + ' - ' + indexToDate(@end).to_s end |