Class: TaskJuggler::Charge
Overview
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.
Instance Method Summary collapse
-
#initialize(amount, mode, task, scenarioIdx) ⇒ Charge
constructor
Create a new Charge object.
-
#to_s ⇒ Object
Dump object in human readable form.
-
#turnover(period) ⇒ Object
Compute the total charge for the TimeInterval described by period.
Constructor Details
#initialize(amount, mode, task, scenarioIdx) ⇒ Charge
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.
26 27 28 29 30 31 32 33 34 |
# 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 |
Instance Method Details
#to_s ⇒ Object
Dump object in human readable form.
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# 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) ⇒ Object
Compute the total charge for the TimeInterval described by period.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# 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 |