class TaskJuggler::Charge
This class describes a one-time or per time charge that can be associated 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/taskjuggler/Charge.rb, line 26 def initialize(amount, mode, task, scenarioIdx) @amount = amount unless [ :onStart, :onEnd, :perDiem ].include?(mode) raise "Unsupported mode #{mode}" end @mode = mode @task = task @scenarioIdx = scenarioIdx end
Public Instance Methods
to_s()
click to toggle source
Dump object in human readable form.
# File lib/taskjuggler/Charge.rb, line 55 def to_s case @mode when :onStart mode = 'on start' when :onEnd mode = 'on end' when :perDiem mode = 'per day' else mode = 'unknown' end "#{@amount} #{mode}" end
turnover(period)
click to toggle source
Compute the total charge for the TimeInterval
described by period.
# File lib/taskjuggler/Charge.rb, line 37 def turnover(period) case @mode when :onStart return period.contains?(@task['start', @scenarioIdx]) ? @amount : 0.0 when :onEnd return period.contains?(@task['end', @scenarioIdx]) ? @amount : 0.0 else iv = period.intersection(TimeInterval.new(@task['start', @scenarioIdx], @task['end', @scenarioIdx])) if iv return (iv.duration / (60 * 60 * 24)) * @amount else return 0.0 end end end