In Files

Parent

Class Index [+]

Quicksearch

TaskJuggler::Charge

This class describes a one-time or per time charge that can be assiciated with a Task. The charge can take effect either on starting the task, finishing it, or per time interval.

Public Class Methods

new(amount, mode, task, scenarioIdx) click to toggle source

Create a new Charge object. amount is either the one-time charge or the per-day-rate. task is the Task that owns this charge. scenarioIdx is the index of the scenario this Charge belongs to.

    # File lib/Charge.rb, line 25
25:     def initialize(amount, mode, task, scenarioIdx)
26:       @amount = amount
27:       unless [ :onStart, :onEnd, :perDiem ].include?(mode)
28:         raise "Unsupported mode #{mode}"
29:       end
30:       @mode = mode
31:       @task = task
32:       @scenarioIdx = scenarioIdx
33:     end

Public Instance Methods

to_s() click to toggle source

Dump object in human readable form.

    # File lib/Charge.rb, line 54
54:     def to_s
55:       case @mode
56:       when :onStart
57:         mode = 'on start'
58:       when :onEnd
59:         mode = 'on end'
60:       when :perDiem
61:         mode = 'per day'
62:       else
63:         mode = 'unknown'
64:       end
65:       "#{@amount} #{mode}"
66:     end
turnover(period) click to toggle source

Compute the total charge for the Interval described by period.

    # File lib/Charge.rb, line 36
36:     def turnover(period)
37:       case @mode
38:       when :onStart
39:         return period.contains?(@task['start', @scenarioIdx]) ? @amount : 0.0
40:       when :onEnd
41:         return period.contains?(@task['end', @scenarioIdx]) ? @amount : 0.0
42:       else
43:         iv = period.intersection(Interval.new(@task['start', @scenarioIdx],
44:                                               @task['end', @scenarioIdx]))
45:         if iv
46:           return (iv.duration / (60 * 60 * 24)) * @amount
47:         else
48:           return 0.0
49:         end
50:       end
51:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.